Idle → Hit Reaction: Player or AI collides with someone else’s attack
Attack State: No mystery here. While the machine is in the attack state the character that the state machine controls is
in the middle of an attack. As I mentioned before a state machine can only be in one and only one state at a time. This
means that while the player is attacking he doesn’t have access to the behaviors in the idle state. Usually this means he
cannot move, or at least cannot move as freely. In general the player must wait until he transitions back into the Idle
state before having access to his entire range of choices again. Here Attack has only one transition, and that’s back to
Idle.
Attack → Idle: Attack ends (Generally means an animation finishes)
The important thing here is that there is a perceptible amount of time spent in the Attack state. It is not the case that
you initiate the attack and immediately return back to idle. As described in the transition description a player must wait
for the attack to finish before returning to Idle. Though the amount of time spent in the Attack state is usually defined by
the length of the attack animation, what actually constitutes as the end of an attack is up to the designer. Just
remember though that returning to the Idle state means that the player has full discretion as to what action to perform;
this includes attacking again.
Hit Reaction State: The machine will enter this state when someone else’s attack successfully hits the character. An
interesting note is that if one machine entered the Hit Reaction state that means that another machine is in the attack
state. This is assuming that the environment did not cause the hit react, which will be the case in many games. The Hit
Reaction state has only one transition.
Hit Reaction → Idle: Hit Reaction ends (Generally mean an animation finishes)
Just like with the Attack state a Hit Reaction almost always means an animation plays. Exiting the Hit Reaction state
means that the animation has finished playing, but as always what actually constitutes a hit reaction is up to the
designer. As I mentioned before, where there is a hit reaction there is an attack, and one of the purposes of the hit
reaction is to reward the attacker for making a successful attack. Another very important purpose of the hit react is to
allow the attacker to finish his attack. Because the attacker is in the attack state he does not have access to his full range
of actions. He is making himself vulnerable to someone else’s attack. By successfully landing his attack and putting his
target in the Hit Reaction state the target also no longer has access to its full range of actions. This exchange between
attack and hit reacts is what I referred to before as a combat phrase and the phrase ends once the target returns to its
Idle state. This relationship between attack and hit reaction is very important to keep in mind, and the amount of time
spent in the Hit Reaction state needs to be comparable to the attack that caused it. This is one of the big areas where
balancing needs to be done, but more on that later.
Defense State: The purpose of the defense state is, as the name suggests, to defend against attacks. It’s the rock to
attack’s scissors. If an attacker lands an attack while his target is idle, then the attack is a full success and the target goes
into the Hit React state. If the attack lands while the target is in the Defense state then the attack is not a full success
and something else happens. Now that something is left completely to the imagination of the designer. The defense
state can be something like a block where the target hit reacts but does not take damage. There are games that use the
defense state for a dodge that have their own rules of success and failure based on timing. A new trend that’s emerging
is that defending means countering an attack where a successful counter initiates its own attack. The defense state is
much more fluid than the other states in the combat state machine and beyond negating an attack it does not have a
concrete definition. However regardless of what “defending” means it occurs in the Defense state. Here’s the Transition:
Defense → Idle: Defense ends (meaning is game specific)
Some games like platformers don’t have a Defense state. This is ok because melee combat is not a central part of that
game experience, but any game where melee needs to be even a little more complex should try to come up with some
kind of Defense mechanism, but it certainly doesn’t have to be the traditional block or dodge.