- Home /
Audio listener options in top-down games. 2D & 3D sounds
I'm having a bit of trouble with my audio levels of 2D vs 3D sounds. See my screenshot for more helpful illustration.
I've a top down 2D game here with an Orthographic camera of size 10. I have a selction of sounds for damage, gunshots, explosions, special moves, and music. The audio levels on these files are all of similar levels, and comparable to normal game sounds and music, so the clips are fine. No need to worry.
The player is the ship in the red circle and the camera follows him so that he's always near the centre, so the red circle represents the player's possible positions relative to the camera at any given time. The ships you see are about 1 unity unit in size.
My music files are 2D sound (naturally) and I want all SFX to be 3D. The problem is that as 3D sounds, I'm a lot further from them. The screen is about 20 units wide but I want to be able to hear everything on screen at roughly equal volumes, and even stuff that's not on screen but is still relatively nearby (see the radar in top-left. The middle circle is roughly the screen but I want to be able to hear (more quietly) into the next circle too).
I've put the Audio Listener on the camera at a height of 10 units above the Z plane (all ships are on 0) to make it so the player isn't WAY louder than everything else and right now the volumes of the 3D sfx satisfy me relative to each other, but overall (and compared to the music especially) they're way too quiet because they're far away.
My music is actually down to 2% volume just to I can hear the sfx over it, and I've doubled the game's master volume (which starts to distort certain sound clips). Even still my game audio is very quiet.
Is tricking around with the logarithmic roll-offs on every single sound the only way to get what I want at normal volumes? Surely there's a better way to be handling this. What I really want to be doing is increasing the 'size' of the audio listener, if you get me. Instead of it being one tiny point on this big screen, that it occupies most of the centre of the screen? I would have thought increasing the size of the camera would have done this automatically..
What are the options, anyway? Thanks guys.
"Is tricking around with the logarithmic roll-offs on every single sound the only way to get what I want at normal volumes?"
AFAI$$anonymous$$, yes. If you've got a ton of sounds to edit, you might consider writing an editor script which can change whole batches of sources in one shot. Note that you might avoid all that work by putting the audio listener on the player's ship, assu$$anonymous$$g the default roll-off works acceptably in that scenario.
Could you do what Sunny says and place your audio listner on your ship, then turn your player ship sound source right down so that it is much quieter, then you can adjust the rest of your sound volumes etc without having to adjust them relative to the player ship sound volume. (You will still have to do what Sunny says and make your $$anonymous$$ distance under vol roll off bigger though :)
Thanks guys. This is a messy kind of fix considering how messy the custom rolloff tool is to try and draw a curve with, and then that you can't save a custom template. What I've done does improve matters, but it leaves me out in the cold for any of the "play audio at source" functions I'm using to play explosions after a gameobject is destroyed. How would I edit those? I'm not sure what you mean by batch editing the sounds with a script. How could I script for a custom roll off?
Have you tried just adjusting the $$anonymous$$ and max values for the roll off, maybe try linear roll off too, if you can get an effect like you want with just these it should make your job a lot quicker and easier.
Do you mean PlayClipAtPoint when you say "play audio at source" ?
$$anonymous$$rSoad, yes, sorry. I meant PlayClipAtPoint (long day :P). I don't know how to give that my custom roll off since I can't save a template and it's not simple linear or log. I've set the $$anonymous$$ and max values to 10 and 50, which are good outlines for me. For the rolloff though, Linear seems to be too loud at distance, and logarithmic is too quiet at distance. It has to be custom from what I'm seeing, but then I don't think I can use PlayClipAtPoint because I don't think I could script for my custom rolloff. Note: $$anonymous$$y custom rolloff is a horizontal line at full volume from 0-10, then a logarithmic-esque curve from full to 10% volume the rest of the way out to 50. Can't imagine how that could be coded for.
Answer by MrSoad · Nov 09, 2014 at 11:55 AM
Hi again, below are some cut down scripts for my exploding mines from my last game. It has the exploding audio source on it, I then use these scripts to make it play the audio, completely disable all the mines components(renderer, collider, rigidbody), and wait until the explosion sound has finished playing before I destroy it(I also waited for the explosion effect to finish, but I've cut that to simplify). I was actually using object pooling so I've adjusted it to destroy for you, you may want to look into pooling though as it can help keep your game running nicely.
function subMine_Is_Exploding(oOther_Object : GameObject) {
//Start Explosion Effect;
oMine_Explosion_Script.bPlay_Explosion = true;
//Play Explosion Sound.
if (!audio.isPlaying) {
audio.Play();
}
//Add Explosion Force to Doomed Object.
if (oOther_Object != null) {
vExplosion_Force_Direction = oOther_Object.transform.position - tMy_Transform.position;
vExplosion_Force_Direction = vExplosion_Force_Direction * (1.0 / vExplosion_Force_Direction.magnitude);
oOther_Object.rigidbody.AddForce (vExplosion_Force_Direction * (oOther_Object.rigidbody.mass * iExplosion_Force), ForceMode.Force);
}
//Start Mine Has Exploded Coroutine.
if (bSelf_Destruct_Started == false) {
bSelf_Destruct_Started = true;
StartCoroutine("subSelf_Destruct");
}
}
function subSelf_Destruct() {
//Disable Mine.
oMine_Mesh.renderer.enabled = false;
oMine_Collider.collider.enabled = false;
oMine_Explode_Trigger.collider.enabled = false;
rigidbody.isKinematic = true;
//Wait until explosion sound has finished.
while (audio.isPlaying) {
yield;
}
//Destroy the Mine.
Destroy (oMine);
}
Something like this may work for your asteroids...
Thanks for sharing. Funnily enough, I am using object pooling. I imagine the difference then is that OnEnable() you want to set the renderers/colliders/etc to active again?
I thought your suggestion might be the only way I have left to go, alright. It's trickier/lengthier than simply playing clip at point, but since I can't do that with the desired roll off (as far as we know) then I suppose something like this is the next best option. Thanks for the help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171041im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
top down camara 1 Answer
First game; Game Manager Question; Spawning enemies! 1 Answer
Top Down 2.5d building game 1 Answer