Demo9a: Controlling character animation with an FSM
Demo9a
showcases a player-controlled character. The player can navigate the character around the terrain using the WASD keys. Pressing the spacebar triggers an attack.
The screenshot below shows an animated character that the player can control to move and perform attacks. The control keys are indicated in green text in the top-left corner of the screen.

Figure 9.2 – The player-controlled character based on an FSM
Building on PlayerFSM
and the PlayerIdle
, PlayerWalk
, and PlayerAttack
states defined in the earlier section, we can now implement the state functions. For the Enter
functions, as mentioned previously, we simply invoke the character’s animation controller’s TransitionAnimation
function. This ensures that the appropriate animation is played when entering each state:
void PlayerIdleState::Enter(FSM* FiniteStateMachine)
{
if (FiniteStateMachine->GetPrevState() == PlayerFSM:...