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?

func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
    velocity.x += 1
elif Input.is_action_just_released("ui_right"):

if Input.is_action_pressed("ui_left"):
    velocity.x -= 1

elif Input.is_action_just_released("ui_left"):

if Input.is_action_pressed("ui_down"):
    velocity.y += 1
elif Input.is_action_just_released("ui_down"):

if Input.is_action_pressed("ui_up"):
    velocity.y -= 1
elif Input.is_action_just_released("ui_up"):

velocity = velocity.normalized() * speed

func _physics_process(delta):
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,121 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 Frequently asked questions and 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.