Cant move even though i specified keys

Godot Version

4

Question

so im new to godot and following a tutorial, i followed every line of code but for some reason my character won’t move in the debug test. the code i used to specify movement keys are
func _physics_process(delta):
var direction = Vector2.ZERO
direction.x = Input.get_axis(“ui_left”, “ui_right”)
direction.y = Input.get_axis(“ui_up”, “ui_down”)
#store the last direction
if direction != last_direction:
last_direction = direction

#update direction and velocity 
if direction.x != 0:
	velocity.x = direction.x * speed
else:
	velocity.x = move_toward(velocity.x, 0, speed * delta)

if direction.y != 0:
	velocity.y = direction.y * speed
else:
	velocity.y = move_toward(velocity.y, 0, speed * delta)

move_and_slide()

Have you tried using the example code provided in Godot Docs?

1 Like

im embaressed , i didn’t attach original script

1 Like

Haha. I know that feeling, man. No worries.
Don’t forget to mark your answer as the solution!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.