Detecting Sound
|
The game’s main mechanic is listening for survivors using triangulation with seismic sensors. To achieve this I created game objects that could be placed out into the world that held a sound file. We wanted the sound to be louder the closer to a sensor it was, rather than just have it play when within a certain radius. To make this work I had to implement a fall-off algorithm. First I tried to just make a simple fall-off where at distance 0 the volume multiplier would be 1 and at distance A the volume multiplier would be 0. This sort of fall-off did not work very well since either the radius of where the sound could be heard would either be too small, or the changes in volume would be to small to pinpoint the origin of the sound. So instead of using a linear fall-off I opted for using an exponential fall-off. After a bit of research in how sound actually works, I found an article describing the inverse square fall-off and the inverse distance fall-off algorithms. In reality, sound fall-off is calculated with inverse square fall-off, but they where similar enough to test interchangeably. This was all done with the Unreal Engine’s Blueprints visual scripting. This is the result that I came up with:
So how this works is relatively simple, however I must admit that my variable names aren’t very intuitive so I’ll walk you through it. First you need a sample point where you specify a given volume at an arbitrarily given distance (variables “Volume Distance” and “Volume at Distance”). To calculate the volume at another distance you multiply your sample point’s volume with the sample point’s distance squared and then divide it by the target distance squared. For inverse distance fall-off it is the same thing but you don’t square the distances. This solution came with a problem, though. As the target distance approaches 0 the volume approaches infinity. First I just clamped the volume from 0 to 1, but this caused everything within a certain radius to have the same volume, making pinpointing the origin of the sound impossible. Instead I clamped the volume based on what the volume would be at a set distance (variable “Volume Clip Distance”) so that I could control the size of the radius where the volume would be the same to make sure it is small enough to not interfere with pinpointing the origin of the sound. I then mapped the clamped values so that the max volume output would always be 1. This solution, while working as intended, proved very difficult to balance since altering the value of any of the three set variables can make drastic changes to the output volume. |
