Prevent playing attack animation until finished?

I’m learning so maybe this is a basic fix. I have standing attack and falling attack animations play once when Z is pressed and only plays again after the animation has finished using variable “hit” BUT when Z is pressed the crouch attack animation plays again before it’s finished. I tried adding a variable “crouchhit” but couldn’t get that to work.

You need to add a condition to your “z key is pressed”, requiring the variable hit = 0. That way it won’t fire off if it’s already 1.

Thanks for the reply. I added hit = 0 on “Z pressed” but now when “DOWN and Z pressed” the attack animation plays instead? I don’t understand what I’m doing wrong :no_mouth:

Mostly because Z and down can be pressed at the same time.

At this point, you’re going to run into more and more conflicts due to the criteria you’re working with.

Rather than trying to do this all on one event sheet, I recommmend working through the Finite State Machine tutorial, it will help you avoid the conflicts you’re seeing. It will take a bit to learn. How to handle complex logic – The finite state machine (FSM) [GDevelop wiki]

1 Like

I see OK thanks for pointing me in the right direction I will use states instead. The way I understand it now is have a main scene and call in external events like player etc from main event?

Yep. This lets you reuse your events on multiple scenes. However, with a Finite State Machine (FSM), this also ensures only the events valid right now are pulled in.

As an example, if you’re doing everything on the same event sheet, and have both a Jump attack and a normal ground attack. You’re going to have to add a bunch of conditions to both attacks to say “not when on ground” or “Not when jumping”, etc. And you could still get conflicts if you’re falling and hit the attack button, instead of jumping.

With a FSM, when you jump you go to your “Jumping” state, which includes your jumping events. You ONLY allow to transition to either: Land and go to your “Idle” state, fall off a ledge and go to your “falling” state, or attack and go to a “Jumpattack” animation and state.

No matter what, the ground attack doesn’t exist as an option as far as the game engine sees, unless you land first. No conflict is possible.

Once you learn more about FSM and are ready to set them up, you might want to plan out your states first. I’ve found this to be very helpful: Finite State Machine Designer - by Evan Wallace

1 Like

Thanks Silvert-Streak to give us your FSM designer! :blush:

Using it, it’ll be clearer to translate states by example to GDevelop actions.