Sound issue when camera has moving parent

Hi,

I am doing some kind of space simulator and needed a camera which follows the space ship with rotation etc. The easiest solution and for now “okay” was to group the camera and the space ship and move the parent through space (A non grouped camera with this behaviour is really hard to find).

So that works till here. Now, the space ship shall have an engine sound. So I created a sound and attached it to the ship. When I now move the parent, the sound is going away and can not be heared.
I found out, that the sound itself is moving with the ship, but the camera position behaves, as it never has been moved.

Does someone knows a fix for that? Thank you!

Hello and welcome!

This may be a bug. Would you mind creating a repro in the playground?

Hi! Thank you :slight_smile:

I will do one in the evening and will add it.

1 Like

Okay, here is the playground example:

you can press w and s to move the box forward and backward.

The first one: https://playground.babylonjs.com/#EDVU95#10 <= camera is not part of the group and box-attached-sound is going away with the box

The second one: https://playground.babylonjs.com/#EDVU95#11 <= camera is part of group and is moving with the whole group, but the sound will go away if you move to far, even if its direct next to the box, which the sound is attached to.

Ok so it is not a bug actually. As you move the camera you need to create the sound with useCustomAttenuation: https://playground.babylonjs.com/#EDVU95#12

1 Like

Thank you!

In your new version of the scene, is still the same behaviour. Do I have to add something else?

Here is a version where the camera is moving, but is not part of the group.

Here the sound is still there: https://playground.babylonjs.com/#EDVU95#13

You need to create the sound like that:

var music = new BABYLON.Sound("Violons", "sounds/violons11.wav", scene, function () {
    }, { loop: true, autoplay: true, useCustomAttenuation: true });
1 Like

I did it, but the behaviour is the same. The sound is going away, even if its next to the source of the sound.

EHHHM. I’m sorry. I seems to work. I don’t know what happened. I tried your playground and I tried it in my own source and it didn’t work. Now I tried that again and it DOES work.

Thank you!

lol ok glad that it works :smiley: