I have a waterfall in my scene.
When i go closer, it sounds louder, when i go far it sounds quieter. All these work perfectly.
But, when it’s blocked by some big rock or something that should do some noise cancellation, it still sounds with the same volume level. Is there any best practices?
The only solution i’ve implemented - add a collider box (trigger), so when the player is inside, it blocks all sounds from the list provided. The same works when i need to apply some effects to the audio source.
Not sure is this the best solution, or if there are some other approaches.
Some advice here will be helpful.
i’ve seen asset store plugins for that (forgot the names though)
raycasting could be one option, check if no blockers in between, adjust audio based on that…
raycasts could even reflect on surfaces few times.
I’ve heard a few interesting discussion about occlusion and obstruction of sound, and got 2 takeaways from them.
- The mass of the object influences how much it absorbs sound
- Frequencies absorption increases on the higher end of the spectrum
So raycasting is definitely on the menu, since you want to assert what kind of object obstructs the sound and its mass to dose the effect. Then the effect itself would not be volume attenuation, but lowpass filtering, to dampen higher frequencies first. To complete a good first version of this kind of system, you’d also have to get a sense of the shortest path the sound can take vs the absolute direct distance.
This is a great game audio system design problem, as you can go reaaaaally deep if you’re looking for something realistic by factoring in…
- the inner material of the obstructing objects
- the reflection at the surfaces of the objects
- propagation volumes and windows
- multiple propagation paths
- speed of sound
- …
I started jabbing at that problem, and the first thing that helped me was to have a way to represent spaces through which sound could travel, some logic to get “strongest” propagation path (graph traversal fun!) and then stack lowpass/attenuation based on the traversed volumes.
And it’s worth mentioning that this applies mostly to “indoor” games. When you’re in nature, you can spare yourself the pain of mapping tree volumes and bushes absorption coefficients and squirrel enthropy… the AudioSource distance attenuation and lowpass should be more than enough for your needs there!
Cheers!