0 votes

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?

in Engine by (29 points)

any code to look in?

It really depends on how you coded this.

1 Answer

0 votes

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.

by (10,582 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 [email protected] with your username.