Let’s Cure Blindness (AI in Unity)
How to let our AI “see” in Unity 2021
When designing games we often need to create enemies that can see our player. Today we will talk about a quick and simple way to give sight to the enemy AI. In previous articles we developed a system that allowed our guards to patrol using a modular waypoint system.
A more sophisticated method would be to use a ray cast from our enemy and react if the ray cast hits the player. This method would be really helpful if our enemies needed to shoot at the player or needed a more precise set of eyes. However for our demo we only need the guards to be able to see the player to trigger a game over cutscene.
We want to do this in the simplest, least expensive way possible. So we are going to use the good old box collider for our guards eyes.
The box collider method works well for this instance because we can setup the details of our box colliders size and allow the OnTriggerEnter() method be what detects when the player is seen by the guard.
Since my guard won’t actually be engaging in combat with the player I will use a box collider directly on the game object. However if we wanted to…