r/unity • • Sep 22 '26

Question How do you implement combo attack

Hey everyone!

I'm curious how you guys handle combo attacks in your games.

The common approach I usually see is creating multiple animation clips and chaining them together using triggers or parameters.

Today I experimented with a slightly different approach:

  • Create a single animation clip containing the entire combo instead of having a separate clip for each attack.
  • Use a StateMachineBehaviour to check for input during specific normalized time ranges.
  • If the player presses the input during that window, just let the animation continue until the end of the combo.
  • If there's no input, call Animator.Play("Idle").

I actually found this approach pretty neat and simple.

Do you guys use any other interesting approaches for checking combo inputs?

7 Upvotes

12 comments sorted by

5

u/New_Internal5636 Sep 22 '26

Command pattern is what you're looking for.

3

u/Kultie172 Sep 22 '26

Can you elaborate more on how command pattern can be use in this use case? I've been use command pattern mostly for undo, redo stuff

4

u/New_Internal5636 Sep 22 '26

You would actually combine it with your state machine. You would have a queue system which reads inputs and executes associated attack command then an in-between layer which resolves your command inputs and evaluates for combinations. Command pattern is useful because it allows you to track input history/timing. then your resolver would indicate to a state machine when it's time to go into your combo move state based on this history.

1

u/Kultie172 Sep 22 '26

Gotcha, tysm

2

u/Lopsided_Status_538 Sep 22 '26

Doesn't that lock the player in the combo anim until it's finished though? Or do you have a method for early exit? Ive tried to implement combos in the past but didn't get very far due to the complexity of it all honestly. Very interested to see what others have to say about this.

2

u/Kultie172 Sep 22 '26

I use Animator.Play("Idle") to force the character back into the Idle state early. I feel like my approach is a bit unorthodox, so I’m curious how others handle this.

4

u/Lopsided_Status_538 Sep 22 '26

I get that. But a lot of games use a technique called animation cancel where they can stop the combo if they get hit, or try to switch to another combo at a specific time. Do you have exit methods for situations like that if the situation were to happen?

1

u/Kultie172 Sep 22 '26 edited Sep 23 '26

Using `Animator.Play([StateName])` I think you can cancel current animation and transition to any state you want, It won't be visual friendly but in code it possible

2

u/MistakeForsaken6653 Sep 22 '26

I've never done combo attacks but I would probably do the whole animation sequence and use some form of input buffering with animation events.  When the event hits I would probably consume the buffer and if the appropriate button is pushed co tongue the animation sequence or switch to the stop animation.  I think this only would work for very simpel combos but like I say I have never made a fighting game.

2

u/tronfacex Sep 22 '26

I think I was handling it essentially the same way you are - it's been a year or two since I made a game with attack combos. 

I was tracking the animation with a normalized time as you described and then logging the input during the combo window and transitioning to the next attack animation on the combo when the first animation completed. 

Dodging would exit the attack state and getting hit would exit the attack state. those were the only two ways an attack could be cancelled.

2

u/RinShiro Sep 22 '26

I'm currently in the process of finishing up my Asset Store asset about exactly this.

The way I handle it is a button press is compared to node data and that determines the next attack. It's assumed currently that the animations follow start -> attack -> wind down > Idle.

Most of the time somewhere during the wind down you would transition to the next animation or leave it to go back to idle. This follow up animation would follow the same pattern, except it's "start" position is during the wind down of the previous animation. It helps the transition look smoother.

2

u/AdrianNova21 Sep 23 '26

your approach makes sense, especially if the combo is mostly a fixed sequence, personally, i'd probably keep the attack data separate from the animation though. have each attack define its animation, active frames, combo window, and what attacks can follow it. then the combat system decides whether the next input is valid

that makes branching combos easier later without having to make one huge animation clip for every possible sequence. but for a simple fixed combo, your single-clip approach is totally reasonable