I am starting to learn gamedev, in specific I would like to make a stealth game.
Ever since I first read about steam audio, I've wondered if it would be possible to use the sound propagation to determine if a npc has heard a sound. There are probably better ways to do this. And not always the most realistic approach is the best approach.
But I've always found that some games are very inconsistent about how npcs hear you. Sometimes you are in a closed room and make very little sound, and they hear you from outside, other times you are in an open place and they don't hear anything. It seems like some games only check the distance to sound origin, without taking occlusion/attenuation into consideration.
I'm no expert but one issue is that "correct" sound propagation needs to handle frequency dependent refraction (why sound is muffled coming from the other room, in additional to leakage through the wall).
One total hack I would imagine would work alright is to render the scene twice, once displayed to the player and the other where the only light sources are the player's sound and walls/windows/etc just have some opacity changed. If the light around the enemy is above a threshold the player is detected. You wouldn't need to render the whole scene, just the area immediately around the player, and avoid doing it if there are no enemies.
Another hack that would be more involved would be to compute a kind of graph for the whole level and when a player makes noise, you propagate it through the graph using precomputed weights. You'd have to handcraft a graph for every level. But I could imagine this getting the best results in terms of performance and gameplay, since you could tune it per scene.
Most games don't have the time budget for that. Visuals take precedence, and it's not easy to get to 60fps as it is, especially if you're doing a lot of other processing.
And stealth games especially will probably rely a lot on shadows and other visual things, which make rendering more expensive.
That's true, I just like when stealth games go beyond just player visibility, some of my inspirations do that:
- Thief Gold, sound was important, each surface would make a certain amount of noise, and you could damp the noise by covering the ground in moss, or reduce it by walking slower.
- Splinter Cell Chaos Theory: which had a sound-meter with 2 indicators, one for the noise you are making and the background noise. I specially like this system because of how it allows you to make much more well-informed decisions.
- Sniper Elite: you can cover the sound of your rifle with loud background noise in some maps, they are regular, and they have cue moments before the loudest part.
Not PvE, but Hunt Showdowns use of sound is worth mentioning. Like you mentioned, every surface has a sound and level, animals react to your sight and sound and will make their own noises, weather and env effects cover or uncover sounds, you can use items or gunfire or anything else to decoy. Really great. All a pvp game so you're trying to sneak up on actual people
I'm not sure if anything has it built in, but Thief: The Dark Project (in 1998) had sound propagation. There's some discussion about it here: https://www.ttlg.com/forums/showthread.php?t=151206. I wonder if you could query Unity's navmesh to calculate the distance, but that wouldn't work with, say, someone on the second floor hearing someone outside through the window.
Wouldn't you have an alternate navmesh for sounds with the appropriate "cost" heuristics based on how well sounds propagates through the mesh's material and across media?
This sounds like a great use of hardware accelerated raytracing. The problem itself is very similar. Sound attenuation can be modelled as transparency.
What you probably want is to place a virtual listener/receiver where the NPC is, so the system would use the same rendering that it does for the player. Then you put an envelope detector on the signal and you have an approximation of how much sound is reaching that NPC.
You could also render the player sound separately from environmental sounds. So the NPC only hears the player if their sound exceeds the environmental noise.
You could get real fancy and do some directional processing on the NPC so they’ll go in the apparent direction.
It’s probably overkill though. You could probably do a much cheaper approximation and it would feel about the same to the player. It would be fun to test it out and see though!
Ever since I first read about steam audio, I've wondered if it would be possible to use the sound propagation to determine if a npc has heard a sound. There are probably better ways to do this. And not always the most realistic approach is the best approach.
But I've always found that some games are very inconsistent about how npcs hear you. Sometimes you are in a closed room and make very little sound, and they hear you from outside, other times you are in an open place and they don't hear anything. It seems like some games only check the distance to sound origin, without taking occlusion/attenuation into consideration.