Implementing the FSM
To create the AI for our chick character, we will be using an FSM, in addition to the line of sight code that we already have. An FSM is not a thing or feature of Unity, nor is it a tangible aspect of the C# language. Instead, an FSM is a concept, framework, or design that we can apply in code to achieve specific AI behaviors. It comes from a particular way of thinking about intelligent characters as a combination of states.
We can summarize the non-player character (NPC) for our level as existing within one of three possible states at any one time. These states are as follows:
- Patrol: The chick is following waypoints around the environment.
- Chase: The chick is running after the player.
- Attack: The chick has reached the player and is attacking.
Each of these modes is a state that encompasses unique behavior, with the chick only able to be in one of these states at any one time. The chick cannot, for example, be patrolling and chasing...