Letting the Enemy See
Tracking the Player Via Colliders
Now that we have our moving Guards AI done, it is time to give them “Virtual Eyes” which allows them to check for the Player. There are various methods in accomplishing this and the solution which I have pick for this project is having an box collider with an script that contains an On Trigger Enter function. This simplistic method is great for quickly testing out game mechanics in a very visual way.
As mention before, our eyes will be created by box collider that is manually placed in front of the Guards. Simply create an 3D cube and have the placement and size adjusted to your desire. Finally have the Mesh Renderer component check off and have the Box collider “Is Trigger” section checked. Also add an Rigidbody component for the Eyes as well since our Player game object does not have one.
We are going to create a new script for the virtual eyes and apply it to Eyes game object.
Since we are only dealing with the On Trigger Enter method, we can delete everything else that isn’t required. In the On Trigger Enter method we will have an IF statement checking for an game object tag called “Player” and when an object called Player is found, the cutscene will be enabled.
To gain access to the cutscene we will create an Serialized Field of an private Game Object called cutscene. Back in Unity we will be able to drag and drop the desired cutscene that we need.