Hearing & Noise
Sight needs a cone and a clear line; hearing works around corners and behind the guard's back. That makes it the sense that turns a stealth game into a game: the player chooses between running (fast, loud) and sneaking (slow, quiet), throws a bottle to lure a guard away, or shoots a lock and brings the whole floor running.
Games almost never simulate real acoustics. They use noise events:
NoiseEvent { position, loudness (radius in metres), instigator, tag ("footstep", "gunshot", "bottle") }Gameplay code reports an event when something makes a noise; the perception system checks which listeners are within range and hands the event to their AI, which decides what to do with it (look, investigate, alarm).
Straight-line range vs. path distance
The simplest test is distance(listener, noise) <= loudness × listener.hearingMultiplier. It's cheap and often good enough, but it lets sound pass straight through thick walls: a guard in the next room hears your footsteps through solid stone.
A better approximation is the path distance: how far the sound must travel through open space. On a grid, a breadth-first flood from the noise does exactly that (see Breadth-First Search); in 3D you can use the navmesh path length, or a cheap room/portal graph.
using System;
using System.Collections.Generic;
string[] map =
{
"###############",
"#.....#.......#",
"#.....#.......#",
"#.....D.......#",
"#.....#.......#",
"#######.......#",
"#.............#",
"###############",
};
var noise = (X: 3, Y: 2);
int loudness = 9; // the noise travels 9 cells
var guards = new[] { ("Ana", 8, 2), ("Bo", 3, 6), ("Cy", 12, 6) };
int[,] dist = Flood(map, noise.X, noise.Y, loudness);
Console.WriteLine(quot;Noise at ({noise.X},{noise.Y}), loudness {loudness}. Digits = steps travelled:");
for (int y = 0; y < map.Length; y++)
{
var row = map[y].ToCharArray();
for (int x = 0; x < row.Length; x++)
if (dist[y, x] >= 0) row[x] = (char)('0' + dist[y, x]);
Console.WriteLine(new string(row));
}
Console.WriteLine();
foreach (var (name, gx, gy) in guards)
{
double straight = Math.Sqrt((gx - noise.X) * (gx - noise.X) + (gy - noise.Y) * (gy - noise.Y));
string byPath = dist[gy, gx] >= 0 ? quot;hears it ({dist[gy, gx]} steps away)" : "hears nothing";
Console.WriteLine(quot;{name,-3} straight line {straight,4:F1} -> {(straight <= loudness ? "in range" : "too far"),-8} | by path: {byPath}");
}
static int[,] Flood(string[] map, int sx, int sy, int maxSteps)
{
var dist = new int[map.Length, map[0].Length];
for (int y = 0; y < map.Length; y++)
for (int x = 0; x < map[0].Length; x++) dist[y, x] = -1;
var queue = new Queue<(int X, int Y)>();
dist[sy, sx] = 0;
queue.Enqueue((sx, sy));
while (queue.Count > 0)
{
var (x, y) = queue.Dequeue();
if (dist[y, x] == maxSteps) continue; // the sound has died out
foreach (var (dx, dy) in new[] { (1, 0), (-1, 0), (0, 1), (0, -1) })
{
int nx = x + dx, ny = y + dy;
if (map[ny][nx] == '#' || dist[ny, nx] >= 0) continue;
dist[ny, nx] = dist[y, x] + 1;
queue.Enqueue((nx, ny));
}
}
return dist;
}Noise at (3,2), loudness 9. Digits = steps travelled:
###############
#32123#789....#
#21012#6789...#
#32123456789..#
#43234#6789...#
#######789....#
#.....989.....#
###############
Ana straight line 5.0 -> in range | by path: hears it (7 steps away)
Bo straight line 4.0 -> in range | by path: hears nothing
Cy straight line 9.8 -> too far | by path: hears nothing
Look at Bo: only 4 cells from the noise in a straight line, so the simple test says he hears it, but he is on the other side of a solid wall. By path the sound has to go out through the door D, along the corridor and back, far more than 9 steps, so he hears nothing. Ana, in the next room, does hear it, because the door is open and the path is only 7 steps. The path test also means closing a door can silence a room: make D a wall and the flood stops there.
Tip: Treat doors, windows and vents as edges in a room graph with a "muffling" cost. Sound through a closed door costs, say, 5 extra metres; through an open one, 0. That's a handful of numbers per level, and it makes level design and sound feel connected.
What the listener does with a noise
Hearing should usually raise suspicion and give a position to investigate, not a perfect fix on the player:
| Noise | Typical reaction |
|---|---|
| quiet footstep at the edge of range | turn toward it, small suspicion bump |
| loud or repeated noise | walk to the noise position and look around |
| gunshot, alarm, a guard's shout | full alert; often shared with the whole squad (see Squad Coordination) |
| noise made by a friend (another guard) | ignore it, which is why events carry an instigator and a team |
Give each guard a hearing multiplier (an alert guard hears better, a sleeping one worse) and each surface a footstep loudness (metal grating loud, carpet quiet). These are the knobs designers tune, so put them in data, not code.
Noise events in engines
- Unreal: the AI Perception system has a hearing sense. Gameplay code calls
UAISense_Hearing::ReportNoiseEvent(World, Location, Loudness, Instigator, MaxRange, Tag), and listeners with a hearing config in theirUAIPerceptionComponentreceive it (see Unreal: EQS, StateTree & Perception). - Unity and Godot don't ship a hearing system. A common pattern is a static "noise bus":
Noise.Report(position, loudness)loops over registered listeners (or does an overlap query with a sphere of that radius) and calls each listener'sOnHeard.
Whatever the engine, report noises from gameplay events (a footstep from the animation, an impact from physics), not from the audio system. The sound the player hears and the noise the AI hears should share one source of truth, or players will notice when they disagree.
Test yourself
Why can a straight-line hearing test feel unfair?
- It's too slow
- Sound passes straight through walls, so guards hear the player in another room
- It ignores the loudness
- It only works in 2D
What should a quiet, distant footstep usually give the AI?
- The player's exact position for the rest of the level
- Some suspicion and a position to investigate
- Nothing at all
- An instant game over
Why do noise events carry an instigator?
- For logging only
- So listeners can ignore noises made by their own team
- Engines require it for audio playback
- To compute the loudness