How How can I make a simple combo combat system.

I’v been trying to make a melee combo combat system in the Unity Animator, but I can’t seem to get it right. I’m trying to go for a combo system that flows from Hit 1 to Hit 2 to Hit 3, ect, with clicks from my mouse, and if I don’t click again it will go back to Idle. How would I go about making this combo attack system in the Animator with C#.

I can see why, maybe, you were drawn to animation - there’s a state machine in your problem and there’s a state machine in the animation stuff.

However, they are different state machines. Animation is about how things look and this state machine is really about how things act.

The state pattern is how we address state machines being a natural component of a problem.

The kind of combo system you are building dictates how you address the state machine.

For instance, if it’s a combo system where successive hits have a cumulative effect, then you need a way to detect how many successive hits have been scored in the most recent run. That amounts to knowing when the last hit landed (e.g., from DateTime.Now), how long a time between hits can be allowed before the combo breaks (e.g., with a TimeSpan), and how long it has been since the last hit (e.g., with DateTime.Now - lastHitTime). Those are just example implementation details. A lot of people would choose to use Time.deltaTime or something. I’m not telling you which is right, just that there are different options that will work.

If it’s a combo system that lives in the input, as in a well-timed sequence of strikes initiates a choreographed “special attack”, then you need something that tracks which potential combos are still available and processes new inputs to narrow that set or detect when a combo has properly been invoked. For most games, you could probably get away with a list of objects that each tracks their own combo state and kicks off the special operation when they are triggered.

If it’s a combo system based on the natural dynamics of various moves (e.g., a back-punch is more powerful after having recently landed a front-punch), then you probably are best off with a classic implementation for the State pattern, like you would find on Wikipedia or any other source: A single abstraction has methods for all the different “events” that can be exerted against the combo system and most of those methods return a reference to the same abstraction. This means that every state has an opportunity to handle each event differently and also to control what the new state is after an event has occurred. If you don’t want to transition the state machine, you just return this.

Check this out it may help you a lot:
link text