I’m making a game where I want an enemy to detect sound that a player is making, if that enemy is in hearing range of the player, and if the sound is loud enough. For example if a player jumps, which plays a sound, the enemy should detect that sound if it is in range and go attack the player.
Does anyone know how one would go about implementing this, or have any nice sources that discuss this?
It’s counter-intuitive, but what you’re trying to do actually has nothing to do with sound - or at least, with the real audible sounds that come out of your players’ speakers and headphones. Yes, you want your game’s enemies to react to the player making noise - but what that really means is you want certain actions taken by the player to alert enemies within a radius, regardless of what direction those enemies are facing. You don’t need to use FMOD for that; all you need is for each “noisy” action that the player can perform to have a defined radius within which enemies will be alerted, and for each enemy’s behaviour script to include how it acts when it is alerted in that manner.
That can be achieved entirely in your game’s code, without needing to build a complex and expensive loudness-measuring system in FMOD.
That being said… It is possible to use the “real” loudness of sounds playing in the FMOD Engine to drive your enemies behavior. I recommend against it, and there are caveats to doing so, but it is technically possible.
All you’d need to do is route all signals that result from the player making noise through a group bus, add a sidechain to that group bus, and link that sidechain to a sidechain modulator that drives a global parameter. Then your game’s code could use the value of that global parameter as a measure of how loud the player is being, and thus of from how far away they might be heard. You’d then only need to ensure each enemy’s behaviour script to includes how it acts when it is within the radius to be alerted by the sound, much like you would in the solution suggested in this post’s first paragraph.
As I said, though, this method has caveats, the most important of which is this: The attenuation applied to sounds by spatialization is based on the distance between the event instance and the listener. The listener is almost always attached to the camera, so unless your game exclusively uses a first-person perspective, it’s likely that the listener’s position will not match that of their avatar - meaning that the loudness of sounds in-game will vary based don the camera’s position, leading to unexpected and unintuitive gameplay.