Chasing the player
The chase state is the second of the three in the chick's FSM. In this state, the chick will chase down the player by running directly toward them.
This state can transition to either of the patrol or attack states. As we've seen in the Chasing the player section, the patrol state requests that the FSM enters the chase state if the chick establishes a direct line of sight to the player while patrolling. Conversely, as we'll see in the next section (Attacking the player), if an attacking NPC falls outside the reach of the player (most likely because they are running away), the NPC resorts to chasing again. From the chasing state, it's possible to move to the patrol or attack state, if the inverse conditions are met.
As with the patrol state, the chase state will exist in its own class:
- Create a
ChaseState
script. We'll start the implementation with theStateName
,OnEnter
, andOnExit
functions:public class ChaseState : MonoBehaviour...