Sound around corners¶
Without help, a sound behind a corner comes straight through the wall, muffled. In real life you'd hear it coming
from the doorway. SpatialReflectionNavigationAgent3D works out how sound travels around walls to reach you, and
places the audio player so the sound comes from the corner it bends around.
Set it up¶
- Add a SpatialReflectionNavigationAgent3D where the sound comes from.
- Add your SpatialAudioPlayer3D as its child.
- Run the scene and walk around a corner from the sound.
SpatialReflectionNavigationAgent3D ← at the sound's position
└── SpatialAudioPlayer3D ← placed by the agent
There's nothing to tune to get started. The agent listens from the same listener as the player.
What it does¶
- Fills the open space around the source with 0.5 m cells, over and under things as well as around them
- Follows sound up and down too: through a hole in the ceiling, a stairwell or a vent
- Works out how far sound travels to reach every cell, in straight lines wherever it can
- Every frame, finds the corner the sound comes around and places the player in line with it
- Gives the player the full route length, so volume and air absorption fall off by the real travel distance
- Makes the sound a little quieter and darker the more it bends (
bend_loss_db,bend_lowpass_hz) - Blends any switch to a new corner over
smoothingseconds, so the sound never jumps - Picks up doors and moving walls on its own, and goes back to plain occlusion when a door shuts
The route is worked out from the listener's position every physics frame. Walking across a corridor or strafing past a doorway moves the sound with you, with no lag.
Check the route¶
Turn on debug_draw_route to see the route: blue when you can see the source, green around corners, red when
there's no route. debug_draw_cells shows every cell the fill reached, and a ring at the fill range.
With the player's display_debug_info on, F4 draws or hides the route and F5 the cells, so you can check
them while you play.
Turn on display_debug_info on the player for its debug panel. It shows the route in its short view, and the full
route details under More (F3). See Debug tools.
Doors and moving walls¶
With watch_for_changes on, the agent watches every physics body near the route. When one moves, it rechecks the
cells around it straight away and fills the space again in the background. A door that shuts cuts the route within
a few frames, and the sound goes muffled through the door. Open it and the route comes back.
Call rebuild() after loading or moving large parts of the level.
Keep it fast¶
fill_rangesets how far the fill reaches, as a share of the player's audible range. It never fills past where the sound can be heard, so a quieter sound costs less- Select the agent in the editor to see the fill range as a green ring
frame_budget_mscaps the time each frame spends filling. The default 2 ms is fine for a few agents- Larger
cell_sizevalues fill faster but can miss narrow gaps - In very large open areas the fill stops at 150,000 cells. Lower
fill_rangethere
A routed frame takes well under 0.1 ms. A full fill of a small building takes around 150 ms, spread over frames.
Every property is listed in the SpatialReflectionNavigationAgent3D reference.