Simple AI Enemy Sight in Unity

There are a few different ways to simulate AI Enemy sight, like raycasting and colliders. In this article, we will look at the collider method.

The “Eyes” of the guard is a child Game Object with a Box Collider set to be a trigger. Since it is a child of the guard, the Collider will move and rotate with the guard.

Next, we create a new script for the Eyes and attach it.

The Eyes script is quite simple. All it needs is an OnTriggerEnter method to detect if the other Collider has the Player tag. If it was the Player, then you execute your logic. In this case, we want to play the captured cutscene.

Hook up the cutscene GameObject.

When the Player enters the guard’s Eyes Collider, the cutscene plays.