Topic was automatically imported from the old Question2Answer platform.
Asked By
Regret666
Its like this if i press left or right the animation walk play while if i press jump the animation play jump but if i press jump while pressing left or right it plays the walk animation in mid air how do i fix this?
The following will play the jump animation when the space-key (i.e. ui_accept) is pressed and play the walk animation when the left- or right-arrow-keys (i.e. ui_left / ui_right) are pressed. However, if you press both, it will play the latter.
if Input.is_action_pressed("ui_accept"):
$AnimatedSprite.play("jump")
if Input.is_action_pressed("ui_left") or Input.is_action_pressed("ui_right"):
$AnimatedSprite.play("walk")
You can switch the order around (or turn the second if into an elif) and you will get the inverse behavior: pressing both actions now will play the jump-animation.
Depending on how exactly you want it to behave, you might need to add further conditions to achieve it, e.g. tracking if the player is in the air or not.