# Alerting enemies to my presence when I make a sound in a Wolfenstein/DOOM style game engine

I am working on a raycast-based 3D game and things are going well, but I am now currently working on the AI of an enemy. I want to make it like how DOOM did it but don't know how to handle how and when an enemy can hear your gunshot so they can "wake up" and become alert.

The map format is a simple grid where 1 represents solid and 0 represents open area.

How did Wolfenstein and DOOM do it?

(My language is Lua with Löve2D if anyone needs to know.)

Thanks in advance for any ideas.

-

I don't think those games used a realistic sound perception model. Probably the best approach is to evaluate the distance between source and hearer and distribute the probability of state change in the enemy.

A gaussian distribution would be perfect but heavy; you may divide the distance in tree ranges: near (always wake), far (never wake), middle (chance to wake).

In the latter case you can degrade the wake probablity from 1 at the "near" end and 0 to the "far" end; a sigma interpolation would be good but chances are that you will not notice the difference beteen sigma and linear interpolation... When you are in the "middle" range roll a dice at each shoot and see what happens.

To add a little thrill you may consider to make the waking up monster to scream so they may advise others slipping neighbors using the same model (play a scream sample would be nice)

The distance can be measured in terms of difference of positions or by casting a ray and summing up the "impedence" of each tile crossed (empty space:low impedence, concrete wall:high impedence). In the latter case the "impedence" can be seen as a lenght measure.

If your monsters don't go around when sleepping, you can consider to take the opposite way by precomputing the sensitive zones for each slepping monster (I suggest you to do this way).

If you want to precompute you may take all the tiles within the audible radius (the radius the moster can perceive with non-zero probability in empty space). For each tile you compute the distance and thus the probablity to wake up the moster standing in this tile.

If the number of tiles are small you may store these results; if not you can summarize these values using macrotiles: 2x2 3x3 and so on tiles wide areas. For each area you associate a chance value that is the average of the chances computed in that area.

The macrotile approach has the advantage to be simple to compute (4x4 macrotile coordinates are the current tile coordinates divided by four), but they may be inaccurate if a macrotile crosses a wall or when there is a large variance between the probablity values of the tiles that make up the macrotile.

If you think that the macrotiles are too rough than you have to tink about a clusterization algorithm and consequently to store those cluster in a more flexible way (a way that is a little harder to compute at run time)

Using a precomputing strategy you can use a better sound propagation model: using the "impedence" model I gave you, you can compute the shortest path and use the shortest path length as distance.

Immagine that the player is in a empty room and between him and the sleeping enemy there is just a single tile wide concrete soundproof wall, using the ray approach you will compute a large "impedence" instance but using the shortest path the sound will "travel" circumventing the wall, stretching a bit the path but strongly decreasing the impedance.

-

Just download Doom (or wolfenstein) source code and have a look at it. Basically it recursively walk into sectors near current player sector, check if there is monsters inside and wake them up.

there is some conditions : eg : if there is a closed door between sector dont go into it (if door is closed monster is not supposed to hear you)

-
Statement about "door closed, cannot hear" is incorrect. You can hear people behind walls, doors. If the AI is smart enough, he should be able to hear -> hide -> surprise you once you enter the door. – joltmode Feb 10 '12 at 9:01