Yes, sometimes you need to do things that way to get more control over input events and not just for movement.
One way, managing variables on _input (always with set_process_input
and set_fixed_process
true):
var movement = Vector2()
func _input(event):
if event.type == InputEvent.KEY && !event.is_echo():
if event.is_action_pressed("left"):
movement.x = -1
elif event.is_action_released("left"):
movement.x = 0
func _fixed_process(delta):
move(speed*movement*delta)
Another, clearing variables on process:
var movement = Vector2()
func _input(event):
if event.type == InputEvent.KEY:
if event.is_action_pressed("left"):
movement.x = -1
func _fixed_process(delta):
move(speed*movement*delta)
movement.x = 0
What works better depends on the game, like, grid based movement may get better result with the second, doing extra position checks before clearing the movement variable and ignoring input event while moving.