Building A Stealth Game — Helping Your Guards “See”

Photo by Wendelin Jacober from Pexels

Repurposing the Collider

As you might guess from the header, what we’re going to do is make use of the Collider feature to “see”. This is not a perfect approach, and we’ll get into the downsides later, but it is a very simple method and can work quite well in some scenarios.

A security guard model with our basic “vision” in place. Note the wireframe box that extends from the guard.

In the script

So at this point, the guard object is detecting when other colliders are crossing the path of its “vision”, but we haven’t yet told the guard what to do about it. This will be done in the script.

The player object Inspector window with the Tag menu open.

What does the guard do?

We have our Collider set, and our script is set up to only run code when it collides with an object with the “Player” tag. The guard has noticed the player, so now what?


I mentioned earlier that we would discuss issues with this approach. As we can see, it’s a very simple approach and easy to set up. So what’s the issue?


This is a very simple and basic method of detection that may not be right for every situation, but is a good place to start thinking about how our AI characters can search for and find things they’re meant to look for.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store