How to Let Your AI See

If you are somehow following my articles, you have noticed that I have been building a 3D game by using Nav Mesh. In this game, the main character tries to sneak to the vault by passing through some guards. So, this article will be focused on creating the mechanism for making the AI agents to see if the Player character passes within their view points.

Certainly, there are more than one way to do it. First things come to the mind are using Raycasting or a Trigger. For this one, I am going to explain it by using a the Trigger way.

It is actually really simple. Create a game object (like a cube) as a child of the character that we want to create eye sight on. Then, change it’s size according to the desire of yours so that the shape will represent the view points of the agent. Then, deactivate the Mesh Renderer of it, and make sure that you have checked isTrigger. Now, all is left is to adding a script so that it will trigger the game if the Player passes through.

In order to make sure that trigger system work, do not forget to add Rigidbody component to the eyes component you have just created. And actually that’s as simple as it is. Now, our AI Agent have eyes!

Unity Developer