Is directional sound possible?

I’m wondering if there is a way to create a sound which emanates from the source in a “spotlight” fashion. That is to say, when you are standing N-meters in front of the source it would be louder than when you are standing N-Meters behind the source, AND --as you approach the ray in which the sound source is pointing in, the sound will get louder (Something like a megaphone, but with more focus). I know I can emulate the effect via scripting but before I do that I wanted to make sure that there isn’t something already built into Unity that I missed.

As far as i know there are no builtin spot-audio-sources in Unity. You would have to emulate it like you’ve mentioned.

There should always be only one audiolistener in the scene and that’s normally at your camera. You can use FindObjectOfType to find the listener in the scene (once in start of course) and then just calculate the angle between the spot direction and your listener position. Vector3.Angle should help.

Just attach the script to your audio source and adjust the volume depending on the angle.

That’s just 2 or 3 lines of code :wink:

Once you attach an audio clip to a game object, you’ll have access to the AudioSource members. With the game object which the audio clip is attached to currently selected, click on the fold-out option named 3d Sound Settings on the Inspector. Edit those settings to suit your purposes.