- Home /
Simulating "hearing noise" like in Jagged Alliance 2...
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 :)
You're not just using an AudioSource to playback 3D audio?
As I wrote, this isn't about playing audioclips that can be heard be the player, co$$anonymous$$g through his speakers, entering his ear etc :) This is about simulating the in-game character's ability to hear and react to sound.
Oh, all right. So what data type are you using for the sounds? A custom class?
Uhm... No, no custom data or anything. It just pass the sound's origin, level and length to a function that adds it it the Origin and Level lists, waits for the duration of the sound, and removes them again :)
function Noise(SoundOrigin : Vector3, SoundLevel : float, SoundDuration : float)
{
SoundOriginList.Add(SoundOrigin);//where the sound originates from
SoundLevelList.Add(SoundLevel);//how far the sound will travel until it can't be heard anymore (linear). 20.0 would mean that it can be heard with a chance of 100% at a distance of 0, 50% at a distance of 10, and 1% at a distance of 20.
yield WaitForSeconds(SoundDuration);
SoundOriginList.Remove(SoundOrigin);
SoundLevelList.Remove(SoundLevel);
}
Ok.. Thanks for the suggestion! I have zero experience with classes or structs but I might finally have to dive into it :]
Answer by mattssonon · Oct 16, 2013 at 02:26 PM
Oh, I'd suggest creating a class or a struct and then store the origin, level and duration inside of it. Then you only need one list for the sound and your code gets easier to maintain if you want to add more properties to the sound. You're also going to have an error if you're looping through a list somewhere while a sound is being removed from it elsewhere.
Your answer
Follow this Question
Related Questions
3D sound crackling problem 0 Answers
Make a noise when i crash into something 1 Answer
sound (audio) makes noise only in timeline 2 Answers
Ambience/Background noise 1 Answer
Screetching Sound While Walking? Why? 0 Answers