0 votes

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)
Godot version 3.3stable
in Engine by (12 points)

1 Answer

0 votes

The animation player doesn't know which of the two animations to play.
Check whether two keys are pressed at the same time too and play one of the animations (diagonally upwards can use the runup animatioan maybe).

by (1,051 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.