3D Sound in Unity

Ryan Sweigart
2 min readMay 1, 2021

--

Desired Result: We have a 2D platformer. We don’t want to hear from all the enemies in the level at once; just those we are close to. Unity makes this easy!

A visual of audio of the zombie’s moans.

First, we give the enemy an AudioSource and set its Volume Rolloff to Linear Rolloff, then we can set the Min Distance and Max Distance to our desired values. In this case, our screen is 16 world units long, so we’ll set the Min Distance to 8. This is the radius in which the enemy’s “voice” will be heard at 100% volume, which is a half a screen away. Beyond that, the volume will drop-off until the Max Distance of 16. This creates the effect we want! If the enemy is over 16 units away, it won’t be visible and we won’t be able to hear it. As the player gets closer, they’ll faintly hear the enemy just beyond the edge of the screen, getting louder the closer they get!

We could use this effect to play a game of “Marco Polo,” where a faerie is hidden in a jar and the closer we get to it, the louder its cry. Rescue that faerie!

Go Bowser! Don’t let those zombies eat your Piranha Plants!

--

--

Ryan Sweigart
Ryan Sweigart

Written by Ryan Sweigart

An independent Unity Developer.

No responses yet