The Great Fleece: Making the Guards See

In this article, I’ll go over how to make the guards see so that they can know when Darren gets into their line of sight.

I’ll be setting this up by using cubes with the Mesh Renderer disabled and the collider set to Is Trigger.

I also change the name to “Eyes.” After adjusting the size and disabling the Mesh Renderer, here is what it looks like on the first guard.

Now I’ll do the same for the other guards. Below, we can see in the scene view that the “Eyes” turn with the guards when played.

Next is to set up the script so that the colliders can detect Darren and then transition to the “Caught” cutscene.

First, I’ll create a new script named Eyes and add it to the Eyes in each of the Security Guards. I can do this all at once but select all Eyes and drag the script into the Inspector.

I also need to add a Rigidbody to each of the Eyes while making sure to disable Gravity.

The script is pretty straightforward. First, create a reference to the GameObject for the Game_Over_Cutscene, which I drag in through the Inspector after saving the script. And in the script, I use an OnTriggerEnter() event set to detect the Player and set the cutscene true on detection.

Now when Darren is caught, it switches to the Game Over Cutscene.

That’s it for setting up the Guards’ ability to see and catch Darren.

I hope you enjoyed this, and until next time I wish you well on your coding and gamedev journey.

--

--

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