Foggy graveyard: spatial horror ambience with plain Web Audio (HRTF) in PlayCanvas

Demo: Foggy Graveyard Audio Demo - PLAYCANVAS
(Click to start audio, WASD to walk, drag to look, click a gravestone or the crypt door. Headphones help. The loops are Ogg Vorbis, so older Safari may not decode them.)

What it does:

  • A fog-covered graveyard with a crypt at the far end. Two ambience stems (bed + detail) play non-spatially and are crossfaded by how far you’ve walked toward the crypt.
  • A second copy of the detail stem runs through its own HRTF PannerNode and slowly circles the graves, so something always seems to be moving just off to one side.
  • A heartbeat loop comes in over the last stretch; a reveal stinger fires from the left partway in, and a jumpscare + impact fires at the ghost near the crypt. Walk back to re-arm them.
  • Clicking a gravestone plays a positioned impact and knocks the stone askew; the crypt door creaks.

How it’s built:

  • PlayCanvas engine only (pc.Application, primitive boxes, exp2 fog, a flickering omni light). No PlayCanvas sound component; the audio is a raw AudioContext created on the first pointerdown.
  • Every frame in app.on(‘update’) the camera position and cam.forward are copied to AudioContext.listener. PlayCanvas and Web Audio are both right-handed with -Z forward, so values copy straight across (unlike Babylon, where z has to be flipped).
  • Stem gains use setTargetAtTime (0.4 s) to avoid clicks; the wandering source just updates PannerNode.positionX/Z along a circle.
  • Picking is a cheap ray vs. bounding-sphere test from camera.screenToWorld, no physics needed.
  • Audio is embedded as base64 data URIs (mono, re-encoded), so the demo is one self-contained ~1 MB file.

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 setup or the wandering-source idea is very welcome.