Making An Enemy AI That Can Detect When The Player Is Close

It seems that most forms of enemy AI these days are developed with some form of detecting the player. Some use sounds, while others use sight, etc.

But how is this done?

The simplest answer is: “Colliders”.

If the player steps over an invisible tripwire around the enemy, then the enemy becomes alerted to their presence. This is often referred to as the enemy's “Cone of Vision” because a lot of developers utilize a “Cone” type shape for their colliders that can detect the player.

The more advanced the AI, the more parameters and collisions go into this feature. From peripheral vision to partially obscured lines of sight defined using Raycasting, these detection systems can become quite extensive.

In my 2.5D Space Shooter game, I added a new enemy type that moves quicker than the others, and periodically flies down to the bottom of the screen to try and shoot the player from behind. But I added the parameter in there for the enemy ship to detect when they are behind the player and shoot.

To do this I added a collider with a longer range extending out in front of the enemy ship. This collider is attached to the parent object of my enemy prefab since It’s bigger than the collider I use to detect when the enemy takes damage. Once all the references were made, I added sets of randomized variables to dictate less predictable behavior, and bam!…

--

--

--

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

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

Recommended from Medium

All About Long- term IT Support and Maintenance Services

Operationalising NiFi on Kubernetes

Everything You Need to Know About Parcel: The Blazing Fast Web App Bundler 🚀

Here’s How To Prepare For A New Development Project: An Engineering Preflight Checklist

Using ReactPHP to run Drupal tasks asynchronously

ReactPHP code

Creating Software Engineering Projects — A Structural Approach

Write Clean and SOLID Scala Spark Jobs

How can I monitor my DevOps journey with a DevOps maturity model?

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
Adam Reed

Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

More from Medium

My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt3

Indy Pro ’22: Talent Training

2D Mobile: Setting Up The Player

Magnetism in Unity Made Easy!