How do you play jump animation even if you press left or right?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

any code to look in?

klaas | 2020-07-20 17:46

It really depends on how you coded this.

p7f | 2020-07-20 18:01

:bust_in_silhouette: Reply From: njamster

That merely depends on the order of things!

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"):

if Input.is_action_pressed("ui_left") or Input.is_action_pressed("ui_right"):

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.