mwg API
    Preparing search index...

    Function audioPan

    • Stereo pan in [-1, 1] for a source: -1 is hard left of the listener, 1 hard right, 0 directly ahead or behind. The listener's facing is its heading in radians (0 faces +x, increasing clockwise on a screen where y grows downward), so turning the listener turns what counts as "right" with it - a sound to the world's east is centred when the listener faces east and hard right when the listener faces north.

      A game with a stereo backend applies this itself; the framework has no panner node of its own, so it reports the number rather than pretending to pan.

      Parameters

      Returns number

      import { audioPan } from '@datamoc/mw_games/audio';

      const listener = { x: 0, y: 0, facing: 0 }; // facing east
      audioPan(listener, { x: 10, y: 0 }); // 0 - straight ahead
      audioPan(listener, { x: 0, y: 10 }); // 1 - to the listener's right
      audioPan(listener, { x: 0, y: -10 }); // -1 - to its left