Playground: Babylon.js Playground
(Click the canvas to start audio. WASD + mouse to walk. Headphones help. Chrome/Firefox; the loops are Ogg Vorbis, so older Safari may not decode them.)
What it does:
- Two ambience stems (a low bed and a “detail” layer of distant movement) loop the whole time. Their gains are ridden by how far you are down the corridor, so the space gets denser as you approach the door.
- A slow heartbeat loop fades in during the last half.
- Stingers are one-shots routed through a PannerNode (HRTF). One fires from your right at the halfway point; a jumpscare + impact fires at the ghost near the end. Walk back to re-arm them.
- Click the door for a creak and the lantern for a boom, both positioned in 3D.
How it’s built:
- No Babylon audio engine, just an AudioContext created on the first pointerdown (autoplay rules). The listener is updated from camera.position / getForwardRay() every frame in onBeforeRenderObservable.
- Babylon is left-handed and Web Audio is right-handed, so z is flipped when copying positions to the listener/panners.
- Gain changes use setTargetAtTime (0.4 s) so stems never click.
- Audio is embedded as base64 data URIs (mono, re-encoded) so the snippet needs no external hosting. That makes the snippet about 1 MB; in a real project you’d load files instead.
About the audio: I’m the creator. All sounds are from my own free sample pack. Its license lets you use them royalty-free in commercial and non-commercial games, apps, videos and other projects, edit and mix them, and ship them inside your finished project; credit (“Sound by yetiancai”) is appreciated but not required. It does not allow reselling or redistributing the sounds as they are (alone or in another sound/asset pack), or registering them with Content ID.
Sounds are synthesized by code written with AI assistance. AI tool: Grok Bot coding assistant (used only to write the synthesis code; current version as of Oct 2026).
This post’s text was drafted with AI assistance and reviewed and edited by me.
Feedback on the listener/panner setup is very welcome.