Patrolling the environment
The first of the three states we'll implement is the patrol state. In this state, we want the chick to walk around the environment, following a predefined route. We achieved this in the previous chapter when we configured an animated Destination
object that jumped around the environment. We'll reuse that object and the associated movement functionality for the patrol state, making a few tweaks to fit our needs. Previously, the chick followed this object without end, whereas the patrol state requires the NPC to consider whether the player can be seen on its route. If the player is spotted, the hunt should begin, and the current state should change to the chase state.
Each state will be contained in its own class:
- Create a
PatrolState
script:public class PatrolState : MonoBehaviour, IFSMState { Â Â Â Â public float MovementSpeed = 1.5f; Â Â Â Â public float Acceleration = 2.0f; Â Â Â Â public...