Formula for audio rolloff?

Hi. I want to determine at what distance (in metres or terrain units) from the audio source the sound volume is zero. Is there a formula involving audio.volume and audio.rolloffFactor? Any experiments I’ve done have left me more confused. (I see Unity 3 handles all this nicely, http://vimeo.com/groups/19470/videos/12852690, but in 2.6 is there a formula?)

yes i have been playing with the rolloff factor in the audio source but cant to get it to rolloff lol i hear the sound all thur my game.What did i go wrong??
or is it me?

Yes,
volume = 1.0f / ( 1.0f + rolloffFactor * (distance - 1.0f));

As you can see volume never reaches 0, so you have to decide on a value that you think is not audible to humans :-).

After 10 years of Unity changes and updates and after doing some testing with the formula above, the Audio Source component and the Volume Rolloff Scale found in the Audio Settings Menu, I found this to be even more true:

v = Volume Distance Attenuation (just the final value that Unity will multiple the amplitude of the audio clip by)
m = MinDistance
r = Volume Rolloff Scale
d = Distance

v = m * ( 1 / ( 1 + r * ( d - 1 ) ) )

Here’s an interactive graph to help people calculate the end result of their audios volume attenuation: Desmos | Graphing Calculator

Note: I don’t think the Max Distance option on the Audio Source does anything.

2 Likes

Great finds! Is there any way to get the Volume Rolloff Scale from script?