# Create attacks that combo into each other

I’m trying to make attacks that combo into each other in my current project. Whenever I press the button, I want a slight delay between the two, and if you don’t press the button, it reverts to the idle animation.
Thanks

1 Like

Hi,
I try to check if I understand with an example: I press button A and if in the time between 0.3 and 0.5 seconds I press A again, the animation “hit” is displayed otherwise the “Idle”. It’s correct ?

So I strongly recommend you map out all of the possible combinations first before implementing anything.

Button combos run the risk of conflicts and very hard to identify issues if you get too far in and change something.

That said, it may make sense to build this as a finite state machine (FSM): How to handle complex logic – The finite state machine (FSM) [GDevelop wiki]

In my mind, I’d have some kind of “lastpressed” variable, and your finite state would look something like:

• If Global Variable LastPressed = “Nothing”
—Go to State “Idle”
• If State Idle
—If attack button A is pressed, set Global Variable LastPressed = “A1”
• If Global Variable LastPressed = “A1”
—If attack button A is pressed, set Global Variable LastPressed = “A1A1”
—If attack button B is pressed, set Global Variable LastPressed = “A1B1”
—If Global Variable LastPressed = “A1A1” AND animation is finished, set animation to “ComboA1A1”
—If Global Variable LastPressed = “A1B1” AND animation is finished, set animation to “ComboA1B1”
—If GlobalVariable = “A1” and Animation is finished, set animation to “Idle”
• If GlobalVariable LastPressed = “A1A1” AND animation is “ComboA1A1”
—etcetcetc

That may not be the best way to do it, but that just quickly comes to mind. Then you don’t have to worry about timers (as it’ll work so long as they hit the other button and the animation isn’t complete).

Be sure you go through the full FSM tutorial before going down this path though, I had to restart building my FSM 4 times because I missed stuff. I feel it is the best way to avoid conflicts, though.

4 Likes

Thanks! This is actually really helpful.
Would this work with enemies too, or would it only work for the player? Either way, thanks! It’s much easier to visualize all of my combos.

1 Like

I would think you could do the same thing for enemies. You’d just make sure you are checking for their variables/animations instead.

Any example with the same button create a 3 hit combo?

1 Like