![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Cuda |
I have a set up animation player and a script set up so that when I click a certain arrow keys it runs the animation in that direction. The problem is that when I press two arrow keys and it goes diagonally the animation stops and doesn’t play anything. How can I solve this?
code:
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
$AnimationPlayer.play("runright")
velocity.x += 1
elif Input.is_action_just_released("ui_right"):
$AnimationPlayer.play("idleright")
if Input.is_action_pressed("ui_left"):
$AnimationPlayer.play("runleft")
velocity.x -= 1
elif Input.is_action_just_released("ui_left"):
$AnimationPlayer.play("idleleft")
if Input.is_action_pressed("ui_down"):
$AnimationPlayer.play("rundown")
velocity.y += 1
elif Input.is_action_just_released("ui_down"):
$AnimationPlayer.play("idledown")
if Input.is_action_pressed("ui_up"):
$AnimationPlayer.play("runup")
velocity.y -= 1
elif Input.is_action_just_released("ui_up"):
$AnimationPlayer.play("idleup")
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)