how to control the character with the button?

dzosekdzosek Posts: 11Member
edited March 13 in 2D

I'd like to move my character left and right using the button

func right_press():
    velocity.x += 1
    velocity = velocity.normalized() * speed

and 
func _physics_process(delta):
    right_press()
    velocity.y += antgravity * delta
    position.x = clamp(position.x, 20, screen_size.x)
    move_and_slide(velocity)

but it doesn't work. The character flies to the right.

Answers

  • SIsilicon28SIsilicon28 Posts: 286Member
    edited March 14

    Well no kidding! you're increasing velocity.x, but there's nowhere I see it being decreased.
    Also, what is calling right_press? The button?

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file