- Documentation
- Client functions
- playSound3D
Function
playSound3D
Plays a sound at a point in the world. It fades with distance from the camera: full volume up to 5 m, silent from 20 m. It is panned left-right.
Syntax
sound playSound3D(string soundPath, float x, float y, float z [, bool looped = false, bool throttle])Arguments
soundPathstring- A path in the resource.
xfloat- X position.
yfloat- Y position.
zfloat- Z position.
loopedbool, optional = false- Whether to loop.
throttlebool, optional- Accepted for compatibility with existing scripts, but the game does not use it.
Returns
A sound element or false.
Example
A campfire radio audible from 40 metres.
local radio = playSound3D("audio/radio.mp3", 2495.1, -1687.4, 13.5, true)
setSoundMaxDistance(radio, 40)
setSoundMinDistance(radio, 8)
Notes
A sound can follow a vehicle. attachElements(sound, vehicle) attaches the sound to an element.
See also
setSoundMaxDistanceSets the distance from which a 3D sound can no longer be heard (20 m by default).setSoundMinDistanceSets the distance up to which a 3D sound plays at full volume (5 m by default). The maximum distance grows if needed.attachElementsAttaches an element to another. The attached element moves and rotates together with the one it is attached to. An object attached to a vehicle is carried by the game in the same frame as the vehicle physics, so it stays exactly in place even at high speed and in turns.