I USE THE attachToMesh BUT DİDNT WORK

I USE THE attachToMesh BUT DİDNT WORK
i can use like this
sound.attachToMesh(meshName)
but it returns an error like this

TypeError: Cannot read properties of undefined (reading ‘x’)

 if (((_a = Engine.audioEngine) === null || _a === void 0 ? void 0 : _a.canUseWebAudio) && this.spatialSound && this._soundPanner && !isNaN(this._position.x) && !isNaN(this._position.y) && !isNaN(this._position.z)) {      | ^  696 |     this._soundPanner.setPosition(this._position.x, this._position.y, this._position.z);

how can i fixed this

1 Like

IT SHOULD BE sound.attachToMesh(mesh) AND NOT meshName :slight_smile:

1 Like

i was using video audio

also how should i set the distance
I want the sound to disappear when I get a little further away
how ı can do it

maybe babylon’s audio will have the function of surround

or this code will be helpful
//////////////////////////////////////////////////
let music = yourMusic

scene.onBeforeRenderObservable.add(() => {
let Distance = BABYLON.Vector3.Distance(yourPlayer.position, SoundObject.position);
if(Distance >2){
if(yourMusic.volume !== 0)
yourMusic.volume =0;
}else{
if(yourMusic.volume !==1){
yourMusic.volume = 1;
}
}