Audio Positional
Updated
3D sound that gets quieter with distance.
- Type
comp-audio-positional- Script class
PositionalAudioComponent- Per entity
- One
- Version
- 1.1.0
Read about it in Spatial audio: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
maxDistance |
0. |
|
refDistance |
0. |
|
rolloffFactor |
0 ≤ x ≤ 10 |
|
volume |
0 ≤ x ≤ 1 |
Events
Section titled “Events”Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.
AudioPositional::readyAudioPositional::errorAudioPositional::playAudioPositional::pauseAudioPositional::stopAudioPositional::end
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Two Audio Zones, a library with rain on its windows and a workshop with a drum loop: their enter and exit events name the room in a HUD label and lower the hall music.
With your sound on, hold A for half a second to walk into the library, or D to walk into the workshop. Inside a room you hear only its own sound, and the label names it. The rain and the beat are short loops generated for this example.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(PositionalAudioComponent); if (component) log(component.props);}