Enemy sound detection

OK, In my game that is a FPS style game, Im trying to do a sound detection, and for this I have many ideas but I actually don't know how to make that in a script so first I want like a combination of sounds that it actually depends on the volume of the sound, the distance between the enemy and the sound and stop where is a obstacle(something like this). And for last I want something like detection with reverb zone so like that it will depend on how far does the sound was to the enemy.

Note: I am using JavaScript and if the answer is a code it would be better :).

Please if someone knows something about this please answer and if you have questions of this question please comment.

instead of actually trying to detect a "sound", you can just set a variable that stores like a noiseLevel, and if the distance from the player to the enemy is smaller than the noiseLevel, the enemy knows you're there.

for example, when you're not doing anything, the noise level is 0. when you're walking it is 1. if you shoot, it is 10. and if the distance from the enemy to you is smaller than the noiselevel, they find you.

As kennypu said, but you could also cast a ray between the player and the sound and 'attenuate' based on what it hits in between. Not exact, but could be close enough.

I also briefly wondered about this, but quickly rejected it as totally infeasible - it would need to be modeled by the physics engine, and you would not only need to model all of the audio sources, and the audio listener, but every material would have to be given values for how reflective and/or absorptive it is... way too much computation.

You could always do a raycast between the sound source (e.g. character) and the "listener" (e.g. enemy) and try and detect any sound barriers between them. If found, you could adjust the sound level/distance calculation. (You would have to decide how to detect the sound barriers and what kind of adjustment to make).

This is actually kinda funny to see posted cuz im going to be working on a solution to this tomarrow.. their's 2 ways Im going to be lookin into.. which ever one works first I'll use or if none work I'll go back to the drawing board... Though the raycasting thing seems like one of the easier ways but Im curious because racast is only in one direction no? so if your not facing the enemy how will that help? or are you talking about doing a spherecast?

the 2 ideas Im going to be trying are:

  1. there's suposedly seperate listeners for this type of situation that can be placed on enemies and depending on how far away you are you can set up the roll off and such to get the distances you want for multiple detections... for me we need it for stealthing around and making sure the enemy can still see you if your right infront of them but muffle the noise in stealth mode so they can only really hear you if your runing, walking, jumping...

  2. My idea is not fully looked into but I seen somewhere you can actually access a calculated distance between objects, from what I gathered it didnt mention a raycast of any sort but I would imagine it would need one. But simular to the above, just use a variable named distance which is Distance and its suposed to calculate distances to what ever you assign it to. Again this isnt fully looked into so there's alot of gaps in it atm.

if I do happen to get it to work tho, I'll be sure to post it here... I too am using JS.

Put this on the enemy but you will need to alter it based on your needs. This is set up for seathling and such... this doesnt take into consideration of walls but you can do a simple raycast or simplly dont put them close to a wall lol

the formatting on here got all wacky so i posted it on one of my blogs the link is below:

Enemy Detection

you will need to reformat the script... didn't c/p the way i had it originally.