Godot Version
Godot 4.3
Question
`Hello, please help me, I just started studying the year from. I want to make the character move 64 pixels respectively by pressing the keys up, down, left and right
Godot 4.3
`Hello, please help me, I just started studying the year from. I want to make the character move 64 pixels respectively by pressing the keys up, down, left and right
Is the character a characterbody2d? Do you mean 64 pixels per second or everytime you click you move 64 pixels?
Everytime when i click
Something like this should do the trick:
const SPEED: int = 64
func _physics_process(delta: float) -> void:
var input_direction: Vector2
if Input.is_action_just_pressed("ui_left"):
input_direction = Vector2(-1, 0)
elif Input.is_action_just_pressed("ui_right"):
input_direction = Vector2(1, 0)
elif Input.is_action_just_pressed("ui_up"):
input_direction = Vector2(0, -1)
elif Input.is_action_just_pressed("ui_down"):
input_direction = Vector2(0, 1)
velocity = input_direction * SPEED
move_and_slide()
Im just assuming you are using a characterbody2d here
This code is working, but character moving only 1px, maybe even less
move_and_slide apparently applies delta automatically.
This should fix it:
velocity = input_direction * SPEED / delta
move_and_slide()