Skip to main content

getListenerPosition

Get the current listener position.

getListenerPosition(): { x: number; y: number; z: number };

Parameters​

This method takes no parameters.

Returns​

{ x: number; y: number; z: number }: the listener position, { x: 0, y: 0, z: 0 } until you move it. You get a copy, so changing it does not move the listener.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();

soundHub.setListenerPosition(3, 0, -4);
const { x, y, z } = soundHub.getListenerPosition(); // 3, 0, -4

// Step one unit forward
soundHub.setListenerPosition(x, y, z - 1);

Good to know​

  • It returns the value soundhub stored, rounded to 2 decimals. It does not read the browser's AudioListener.
  • When spatial audio is off, setListenerPosition returns early and this keeps returning the old value.

See also​