I’ve been hard at work for a few days implementing a system that allows sounds within the game to change their properties based on their physical surroundings. Previously I have designed a system like this for my previous game Vampire Hunters 3, however that one required a ton of manual labour to set up the reverb factor for each area of each in-game map and was not truly ‘dynamic’.
This new system makes use of the recently release Audio API - allowing for more intricate control of audio within Roblox. I’m aware that it was mentioned recently on the public API release thread that Roblox engineers already have plans on this as an official feature, but I can’t count on it being produced for at least another year.
The setup
I have a data set of materials to reference from that each have attributes that control how audio is affected by them, in terms of hardness/absorption and reflectance.
Each sound marked as ‘spatial’ will have this template fader wired into it and chained correctly:
Pseudo code flow chart of me trying to understand wiring & how this system would work
When the AudioEmitter source point is obscured from the camera behind a wall, it will then try and see how closely connected it is to the player using PathfindingService*
*Built-in Pathfinding is NOT a perfect solution for this, as it is built for entities that abide to gravity.
Therefore, obscured audio is unnaturally more muffled if the sound is behind a wall that is across an unreachable gap, or if the sound is below a player blocked by an open platform with no easy way up. I debated creating my own 3D-space pathfinder using a volumetric grid, but I have tupid and only got as far as creating an occupancy grid. Plus, any pathfinding algorithm I could implement would be far less optimised than the inbuilt pathfinding designed by professional programmers.
This system has to be refined and performance costs have to be taken into account, as each spatial sound adds AT LEAST 15 more instances (faders, effect chains, wires etc.) for what would have been ONE single Sound instance. Also, it uses a lot of raycasting, so I have set it up so that some sound effects have a ‘fast’ mode that uses less raycasts and no muffle pathfinding.
Despite these flaws, I am pleased with the resulting system. It adds a new depth of polish & immersion to my game world by making the player feel more immersed in their surroundings!
The demo
Demo video 1:
Material acoustics
Demo video 2:
Showing off how a streaming source of music is effected by its environment and relation to you