I’m currently contemplating how to script a noise system as seen (or rather, heard ;)) in games like Jagged Alliance 2. When someone walks a tile it produces a footstep noise, if a gun is fired it produces a gunfire noise, explosions, etc.
This is NOT about playing actual audioclips! This is about how to implement a system where noise effects are stored for a short period of time during which other characters have a chance to hear them, based on sound level, distance, and even hearing ability, and if they are heard by one character, giving him a cause to go investigate.
It would theoretically be possible to instantiate a seperate “noise” gameobject each time a sound is made, but this would become cumbersome if many characters are shooting or even walking at the same time.
So far, here’s how I did it:
If a noise is caused, it is added to two global lists: The SoundOrigin list that stores the Vector3, and the SoundLevel list that give stores how loud a sound is. The noise information from this particular noise gets removed from both lists after the duration of the sound effect.
Every character has the chance to hear all sound effects currently stored in the global list, dependent on distance, sound level, and hearing ability. If he hears it, it’s origin gets added to a personal list of PointsOfInterests (Vector3) which he can refer to if he decides to investigate.
Now I’m looking for other ways to do it, maybe someone has achieved a working system? I’m not looking for actual code, but rather theoretics.
If this kind of question doesn’t belong here, please just close, thanks