Godot Version
Godot v4.2.1.stable - Ubuntu 23.10 23.10 - X11 - Vulkan (Forward+) - integrated Intel(R) Graphics (ADL GT2) () - 12th Gen Intel(R) Core™ i7-1260P (16 Threads)
Question
Trying to figure out how to attack while walking animations. I walk holding down D key, and press the Right arrow key to attack. I would like it start playing the attack animation while still keeping down the D key and upon release of arrow key to go back to walk.
Is there a way to interrupt the held down D key and give priority to arrow key pressed?
For example do I need some flags to ignore the D key and is _is_action_just_pressed() the function to use?
func _process(delta):
# attack/Slash right arrow key
if Input.is_action_just_pressed("ui_right"):
$Sprite2D.flip_h=true
anim.play("attack") # Slash animation
horizontal_direction = 1
velocity = Vector2(speed * horizontal_direction, 0)
move_and_slide()
# walk pressing D
if Input.is_action_just_pressed("move_right"):
$Sprite2D.flip_h=true
anim.play("walk") # Walk animation
horizontal_direction = 1
velocity = Vector2(speed * horizontal_direction, 0)
move_and_slide()