- Home /
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.
Answer by Bunny83 · Jul 25, 2011 at 10:03 PM
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 ;)
Thanks bunny. Thats what I figured I would have to do, but I thought maybe--just maybe-- there is a better optimized built in way of doing it. Something for a future version perhaps? :)
Answer by Dreamblur · Jul 25, 2011 at 09:25 PM
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.
I'm aware of this. The problem is that the 3d-sound settings don't seem to offer any way to "point" the sound in a specific direction. At first I thought that maybe that is what the "spread" was for. It seems, however, that the spread just deter$$anonymous$$es whether the 3d sound emanates in stereo or in mono. I'm going to go ahead an assume that this actually isn't built into Unity. Thanks for the answer anyway.
Your answer
Follow this Question
Related Questions
3D-audio-source limit 0 Answers
Attach audio source to different part of object 0 Answers
Making Audio sound like it's behind you in a text game 0 Answers
Repurposing the inspector graph module 2 Answers
Need help with 3d sound 2 Answers