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
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
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.
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.