- Home /
Audio Source AI Attractor
Hi everyone
Well right now I am making a Zombie Game and i was wondering how i would make it so that zombies in range of a certain audio source would move towards it, help would be greatly appreciated
Answer by Ricardo · Nov 27, 2009 at 05:45 PM
This is related to audio sources only in that's the way you conceive it as a human being. From an abstract standpoint, what you need to do is figure out which objects a zombie would be attracted to (in this case likely a player, a gun, a firecracker, etc) then evaluate proximity of the zombie unit to an object of this class.
There are many ways to do it, from a proximity database (look up Octrees if you'll have a ton of these) to simply using a trigger for detecting when the object gets close enough to a zombie.
As an example, you could take a look at the radar examples on UnitySteer, or for a much more trivial case (on an older, likely outdated article) at Proximity detection with triggers.
Answer by Jaap Kreijkamp · Nov 28, 2009 at 02:17 AM
A simple solution is making a custom PlayOneShot function that besides playing the audio at point in space also notifies zombies in range. A simple way to do it is placing zombies and chars that must be able to hear in a special layer and call in the MyPlayOneShot:
foundList = Physics.OverlapSphere(*pos_of_audio*, *radius_related_to_loudness*, *hearingLayer*)
and go over the returned foundList array and send message to gameobjects with the position of the sound.
Your answer
Follow this Question
Related Questions
Efficient spatial searching (finding game objects within a certain range) 2 Answers
How to make AI enemy do damage and only attack inside a distance or range 2 Answers
Detect player in range of enemy... 4 Answers
enemy waypoints and detection scipting 2 Answers
getting enemys to follow character. 1 Answer