Attack animation only works once until player moves

Hey guys, I’ve been tinkering with GDevelop for a few weeks now (and it’s awesome by the way) and most problems I’ve managed to solve myself or with a simple search.

This latest problem has me stumped and nothing shows up when I search. Search results only seem to show problems with the animation only playing one frame. I managed to sort that problem but now my character will attack once and then the attack button does nothing until I press another key with a different animation such as walk or jump.

I’ve tried many things like disabling all other code to find a conflict but it’s not any of the other code causing the problem.

My code for the attack is simply “key is pressed - Change animation to attack”

Do I need to do something else to reset the animation so it will play again. Like I said above, if I walk just a single step or press the jump button once it will then allow me to attack again!

Screenshot below

Never mind I figured out a way. Not sure if it’s the ‘prettiest’ way but it works.

I just played around with wait x seconds so the animation would complete after releasing the attack button then set the animation to idle.

No idea why my other code to return to idle animation after all other events wasn’t working.

1 Like

I’m going to assume the loop box of the attack animation is unchecked to prevent it repeatedly attacking with one button press. The issue is that if you use a “change animation” action but the animation is still the same, then GDevelop doesn’t reset it. It just keeps playing the current animation.

The fix is to add an action, after you set the animation, which sets the current frame:

Also add a trigger once to the event, otherwise the animation will stay at the first frame until the b key is released.