AI Hearing in Unity: Sound Events, Distance Falloff, and Wall Occlusion
Build useful AI hearing in Unity with a global sound event bus, intensity-based range, sound categories, wall occlusion, material attenuation, and debuggable reactions.
Represent sound as an event, not a permanent object
Footsteps, impacts, gunshots, doors, and shouts are moments. Polling every possible emitter from every guard wastes work and makes one-shot sounds awkward to model. Instead, publish a lightweight sound event containing a position, intensity, category, source, and optional lifetime.
Hearing sensors subscribe to that event stream and decide whether the sound matters to them. This keeps emitters independent from listeners and lets the same event wake one nearby guard, mildly interest a distant guard, and be ignored by a distracted guard with a weaker hearing profile.
Let intensity define an effective radius
A sound should not be a binary sphere. Give each event a base radius or loudness, reduce its strength with distance, and apply a listener profile. A gunshot can begin with a large radius, a footstep with a small one, and a thrown bottle with a short but sharp impulse.
Keep authoring language practical. Designers understand quiet, normal, and loud more quickly than acoustic units. Internally, convert those choices into a normalized value that awareness can consume consistently.
- Footstep: frequent, low intensity, usually capped at mild suspicion.
- Impact or lure: medium intensity and a strong investigation target.
- Gunshot or explosion: large radius and high priority.
- Voice or radio: category-specific rules for allies and factions.
Occlusion should attenuate, not always erase
A wall between the listener and sound source should usually reduce a sound rather than delete it. Cast from ear height toward the event and apply attenuation when the ray meets an occluder. Thick concrete may reduce a footstep below the threshold while a gunshot still gets through.
If the game needs more control, attach an acoustic coefficient to important materials or objects. A closed metal door, thin wood wall, open window, and dense bunker can then produce different results without rewriting the hearing sensor.
Use one clear, tunable approximation before attempting expensive propagation. Consistent gameplay is more valuable than a physically perfect simulation.
Separate hearing a sound from understanding it
Detection answers whether the event reached the guard. Interpretation decides how the guard reacts. A weak footstep might only turn the head. A repeated lure can start an investigation. A confirmed gunshot can alert the guard without granting a valid target to shoot.
This distinction prevents phantom combat. Hearing can raise general alarm and establish a location, but only a combat-qualified sense such as direct sight should authorize an attack unless the game deliberately supports blind fire.
Show why a sound was heard or ignored
Log the original intensity, distance falloff, category weight, occlusion multiplier, listener profile, and final contribution. In the scene, draw the event radius and the ear-to-source ray for the selected guard.
This turns common problems such as an incorrect layer mask, ray starting at floor level, or a sound category with zero weight into visible configuration issues rather than mysterious AI behavior.
Argus already connects these pieces.
Argus packages perception, awareness, memory, suspicion, search, squad coordination, and live debugging into a drop-in Unity 6 system. Use the included guard or subscribe to its events and keep your existing movement, animation, combat, and character art.