Jump to content

make the player "audible" for enemies


DudeAwesome
 Share

Recommended Posts

Hey guys,

 

I´m looking for a solution that the bad guys in my game can hear me.

 

Every sound (source) have a range but I need something like "ears" to get a notice if a sound is audible or in range to an object (specific position of an enemy).

 

I need an object or some kind of listener for each enemy that observse if there is a sound played with a specific key. The key is used to indicate if the sound (source) is coming from the player (footsteps, shooting etc) or from the map (ambient sounds etc). if the key that was detected is from the player than the enemy move to that point.

 

Maybe its a good option to add more functions to listeners like:

 

Listener:AudibleSources()

 

that returns an array with all entities of sources that are in range and audible

 

 

with that functions I could ask the array for the keys (is that sound from a player?)

 

if I find a key like "fromPlayer" I will ask the position of the entity and the enemy uses the navmesh to go there.

 

if would also be nice to ask whats the volume of a sound (source) from a specific point. If the point is in range of the sound it should be between 0 and your Source:SetVolume() value. If not its 0.

 

Listener:GetSourceVolume(*source)

 

returns the audible volume (float) of the source from the listener position.

 

 

is there a other way to do this? This functions would really help a lot

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

I wouldn't think you'd actually use any sound data for this. I would throw a custom AABB around your player and loop over every entity in the AABB (ForEachEntityInAABBDo) from within the player UpdateWorld(). Track some kind of sound volume variable and if it is high enough alert the enemy entities that are in the AABB. You could also do distance checks for each entity found in this bounding box and based on the value of the sound volume/strength and the distance decide to alert that enemy entity or not.

Link to comment
Share on other sites

I also have the AABB solution in mind but I dont like it.

 

with AABB I could check if there is a source entity in range but the problem is that I have to calculate the volume that the AABB receive. AABB is ok for collisions but a sound is not only a collision. It also have a range.

 

this fact gives me other problems:

 

eg.

 

Case - Player audible range is to small and Source is far away

 

I have a source that plays a sound 100 units away from my player. The range of the source is 120 so the player will notice it when he moves 20 units to the source entity if the player audible range is 80.

 

(player range is size of AABB)

 

to avoid this I have to set the radius from my AABB to the maximum RangeValue from all sources.

 

The AABB solution is also not the best performance option because I need a sphere or a cylinder here for collision detection

 

eg.

 

I have 5 sources

 

1. Range 5

2. Range 5

3. Range 25

4. Range 27

5. Range 190

 

I have to set the audiable range radius to 190+ and have to check all entities here. so if I use a cube for AABB it I have to check 190*2 units in all directions (xyz) just for one enemy.

 

I also dont want to give the player some kind of audible range and calculate it every frame. In real world we also dont have a audible range. hearing is just input. yes or not. so ears are some kind of observer. Its a good example to use observer/listeners here

 

 

 

 

 

It should already be implemented into leadwerks. When I have a listener that calculates the volume of my sounds there have to be a function that gives the leadwerks engine something like "getSourceVolume()" because when my player character is in front of an source entity the volume is the highest in my speakers. when I move away the volume goes down in my speakers. Something have to tell my speakers which volume the sound have to play. So I believe those functions are already implemented but not public. I also would like to use the listener as a listener (observer) because thats what a listener is there for but there are no functions available in leadwerks.

 

I also dont want to calculate it every frame because its very bad case. I would like to do it event driven.

so no range for the player only ranges for sounds (sources). if a listener notice one or more sources (because its in the range of the sources) I will ask for a array/list of source entities and its volumes.

 

I want those functions public accesible for all leadwerkers. I think there is a lot capability for the listener class

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

And how do you think this would be done in Leadwerks?

josh code the stuff for me biggrin.png

 

no just kidding but I think something like this could be very useful for other users. I dont think something like this would be coming soon but sometimes I would like to do some more advanced stuff but I cant do it with leadwerks because the available classes and functions are very clearly. I just want the best for leadwerks. I really like the engine but I´m missing something here and there.

 

for example leadwerks have native OpenAL support. But when I would like to do some more advanced audio stuff (like effects or filters) I have to buy the cpp version include OpenAL library again and have to code my functions by myself.

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

..actually, its rather simple to do that..it doesn't require any additional checking, but volume check..now, what im about to say is based on my understanding of Leadwerks 3, i dont have, but i expect that simple command set for sounds are same as LE2.

 

..if you want your enemies to hear you(main character), basically, you will simply, attach 3D sound you want enemy to hear to each enemy with EXACT settings your main character have..by saying attach 3D sound to enemy, I mean, keep position 3D sound you want enemy to hear, to exact enemy location..lets call that sound a marker sound. Marker sound should be just silence, 1 sec or so. Now this is what you do:

 

1) Load marker sound with exact settings as sound you want enemy to hear from main player, such as footsteps, and so on(range, etc)

2) Play marker sound(silence) in a loop, so you cant hear it anyway

3) Every time enemy moves, reposition marker sound at enemy position

4) Every time main character moves, check VOLUME of your marker sound(this depending are you want to listen walking sounds or reloading weapons, etc, adjust check based on this and individual marker sound)

5) If marker sound volume is over 0.0, enemy HEAR your main character

 

On the top of this, you can add any additional check such as visual sighting, etc, to improve your AI, if you want to..

 

This will do..tested and it works..

I hope it helps

 

Link to comment
Share on other sites

The listener object is not for handling ai sound handling etc. There is only (or better should be) one listener in your world, the one for the player. This listener only handles how the sound is computed for your soundcard or other output devices. For handling ai to react on sounds i would implement a derived source item.

 

This derived item would establish a collision sphere as a trigger with a radius of the maximum range of the sound source.

Now you check if an enemy enters or leaves the trigger.

If the enemy enters, the enemy subscribe to an event handler, if it leaves it unsubscribes it.

 

Now if you need to emit a sound you tell the source which sound and key it should play and the derived sound emitter will emit the sound and emit an event to each subscriber. The subscriber can now handle the details in its eventhandler.

 

I will check if i can generate a small prefab and sample later.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

I thaught 3D audio to be integradted in most 3D engines ?

I mean, you have some ennemy, just add sound object as child (sound with some volume value)

When ennemy moves, you just play sound in loop in your code , that's all.

As player you will hear the volume less or strong depending on your position automatically.

 

It is not integrated in 3D Engines ?

Stop toying and make games

Link to comment
Share on other sites

The listener in LE3 works as intended and the same as in all 3d engines with sound. For the scenario DudeAwesome wants to achieve you have to create your own listener object with handling sound sources and bubbling events to receivers.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...