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.

--

--

--

Unity Developer, Software Engineer, Game Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Simple Python Code snippets

Python & SQL: How to enable the execution of python scripts within SQL Server

Debugging PHPUnit Tests Variable in Laravel

Some Easy Actions in order to help You Put a MattressCover https://t.co/XD9a6iGYnw

Provide More Information About Your Product to Your Customers Using PDFs

READ/DOWNLOAD$< C++ The Core Language: A Foundation for C Programmers (Nutshell Handbooks) FULL…

Kafka on Kubernetes: Strimzi vs Confluent Operators

Web Conversations With the Year 2000

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
Kyle W. Powers

Kyle W. Powers

Unity Developer, Software Engineer, Game Developer

More from Medium

Understanding Frustum and Occlusion Culling in Unity3D

Ledge Grab System: Part IV

Adding a ram attack to our boss

Journal 136 — Unity App Development, AR using Vuforia