Keybinds not working

Godot Version



The Keybinds on my Godot 3d project are not working in the way that when I open my project in play mode the inputs don’t work can any help with my problem

It might not be a problem with your keybinds. Can you post your code here?


In addition to copy-pasting your code here, can you take a screenshot of your Input Map?


sure thing

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta

# Handle Jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = JUMP_VELOCITY

Get the input direction and handle the movement/deceleration.

# Note that the negative value for the forward/back movement is because Godot's forward is -Z
var input_dir = Input.get_vector("left","right","up","down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	velocity.x = direction.x * speed
	velocity.z = direction.z * speed
	velocity.x = move_toward(velocity.x, 0, speed)
	velocity.z = move_toward(velocity.z, 0, speed)


That all looks like it should work from my POV. That looks like basically the CharacterBody3D template Godot gives you, but you’ve switched the inputs with your own which you added to the Input Map. That all seems good. Have you tried adding some print statements to see what if anything your code is doing? Try pasting this at the top:

	if Input.is_action_pressed("up"):
	if Input.is_action_pressed("down"):
	if Input.is_action_pressed("left"):
	if Input.is_action_pressed("right"):
	if Input.is_action_pressed("jump"):

See if those print.

ok i’ll try it

I now have this error for something else that stopping me from starting the project

If you haven’t fixed it yet, please do copy and paste the line of code as it got cut.

From what it reads, though, seems like input_dir is not declared or is out of scope.

1 Like

i fixed thank you though

Yes; I’ve just noticed it was an indentation problem.

Is Input working properly now?

yes it is

Could you mark the correct reply as solution with the :white_check_mark: symbol?

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