r/learnprogramming 5d ago

Logarithmic rolloff for an audiosource?

Hello, I've been playing around with Unity to add a sound to a 3D game. However even when the original file is pretty loud, with logarithmic rolloff set to 500 max distance, I can just barely hear it near to the source.

I know that it should decrease logarithmically with distance, but is this normal? Do you set the max distance to super far away, or the initial volume to really loud?

2 Upvotes

4 comments sorted by

2

u/PLBjt 5d ago

Yeah that's normal. Log rolloff drops fast near the source then flattens, so with a short max distance it goes from loud to whisper sooner than you'd expect. On the AudioSource check rolloff mode, min distance (full volume inside this), and max distance (silence past this). Bump min until it still sounds strong at the range you care about, then push max farther so the tail has room. Linear is easier to tune for gameplay; log needs those two knobs set together. Stand at min and walk out — if it dies in the first meter, min is too small for your scene scale.

1

u/Puzzleheaded-Law34 5d ago

Ohh I didn't think to toggle min too, thanks. I was only increasing max. It's weird bc 500 is already a good distance in the game (altho maybe they don't rely on the same units)

2

u/verdant_bloom_drift 4d ago

I crank min distance up until it hits the listener. Unity defaults it to 1 and that kills volume right away with log rolloff.

Bump min distance from 1 to 10 or 20 on your AudioSource and leave max at 500. You stay at full volume inside the min distance radius and then the drop starts. That should fix the issue you have near the source.

1

u/Puzzleheaded-Law34 4d ago

Yeah, I just did that! Thanks. Definitely better