Input.get_vector function is not recognising positions when keys are pressed

Godot Version

4.2.2

Question

I started doing a tutorial by Clear code for reference
extends Sprite2D

Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
var direction = Input.get_vector(‘Left’,“Right”,“Up”,“Down”)
print(direction)

and instead when my code is supposed to give the desired output when pressed the keys, it gave this instead;
(0,0)
(0,0)
and so on

Can this be fixed?

Do you have 'Left', 'Right', etc set to be actual input actions in your project settings? In:

Project > Project Settings > Input Map

The default names for these are "ui_left", "ui_right", etc, so if you’re using custom names, then you need to make sure those are mapped to real keyboard keys. The strings for these actions in your get_vector() call MUST be identical to the ones in your Input Map.

1 Like