Providing the enemy with sight
Let's now start developing the enemy AI by thinking about our functional requirements. The enemies in the scene will begin in patrol mode, wandering the level from place to place, searching for the player. If the player is spotted, the enemy will change from patrolling and begin chasing the player, attempting to move closer to them for an attack. If the enemy reaches within attacking range of the player, the enemy will change from chasing to attacking. If the player outruns the enemy and successfully loses them, the enemy should stop chasing and return to patrolling again, searching for the player as they were doing initially.
To achieve this behavior, we'll need some method of determining whether the chick can see the player as the chick relies on being able to see the player to decide whether it should be patrolling or chasing:
- Create a new script called
SightLine
to represent the chick's sight:public class SightLine : MonoBehaviour...