0 votes
extends KinematicBody2D

var velocity = Vector2()

func physicsprocess(delta):

if Input.is_action_pressed("ui_right"):
    velocity.x = 30
elif Input.is_action_just_pressed("ui_left"):
    velocity.x = -30
else:
    velocity.x = 0
move_and_slide(velocity)

moving to the right works perfectly but to the left it moves like 30 pixels to the direction inmediatly and then stops.
I been following a tutorial and everything is the same.

asked Oct 12, 2019 in Engine by TomisOps (12 points)

1 Answer

+1 vote

Left movement doesn't work because you wrote the wrong command:

Input.is_action_just_pressed("ui_left")

versus

Input.is_action_pressed("ui_right")

is_action_just_pressed() only triggers on the first frame where you press the button, and will not trigger again until you release and press it again.

answered Oct 12, 2019 by kidscancode (13,248 points)

oh my bad. thank you

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.