Allow Your Player To Distract Your AI By Throwing An Object

This is a common mechanic that you see in a number of Stealth games. Throwing rocks, creating noises, or flicking coins to distract your enemies in order to sneak around or get the jump on them. The concept is quite simple, but how would you go about implementing this into your own project?

Well, let me start by explaining two different ways that you could go about this. First off, let's discuss the object throw.

You could have an object with gravity be instantiated in front of the player position and apply force to launch it outwards assuming you're developing a physics-based game. Then upon impact use “OnCollisionEnter” to spawn an object that contains a “Trigger Collider” at the point of the collision. Use that trigger collider to represent the range that the object's sound will carry.

Then add an “OnTriggerEnter” method to the AI’s script to detect the collision and change their state of behavior!

Another option on how to handle this is to use your mouse to select a point and it spawns an object at that point. Then you can use “FindGameObjectWithTag” to locate all of the AI with that tag and have them be drawn to that position!

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!

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