Attaching sound to a specific object (not the rootNode)

I’m trying to make a flaming object, the burning object obviously emits sound and I want that sound to stay on the object, getting quieter as you leave. Right now the sound is playing like ambient environmental noise and no matter how far I toss the object away the sound won’t leave the user.

I have a Node with a ParticleEmitter, a Spatial and a Sound attached to it.

[java]
Node bulletPackage = new Node();

//.. Some code here to set up a particle emitter named fire
bulletPackage.attachChild(fire);

//.. Some code here to set up a spatial object named bullet
bulletPackage.attachChild(bullet);

bulletFire = new AudioNode(assetManager, "Sounds/Fire.wav", false);
bulletFire.setPositional(false);
bulletFire.setLooping(false);
bulletFire.setVolume(1);
bulletFire.play();
bulletFire.setRefDistance(50f);
bulletPackage.attachChild(bulletFire);

rootNode.attachChild(bulletPackage);

[/java]

I know that the setRefDistance is 10 by default but I hoped maybe tampering with that (or max distance) would help. These did not affect the audio. The audio follows the user around and doesn’t seem to actually be attached to the Node I put it in.

I’m a noob, so it’s probably a noob error, but I just can’t figure this out.

bulletFire.setPositional(false);

…you want positional sound but set it to ambient…

Also, just a heads up that you will need to setup and update the audio listener (poorly named just Listener). The positional sound tests show this.

1 Like

Okay. I tried that, but I got the:

“IllegalStateException: Only mono audio is supported for positional audio nodes”

error so I guess I need to use different audio files? I’m not an audio guru or anything but thanks for the tip. As far as updating the listener you’re referring to the location and rotation updates in the simpleInitUpdate methjod? I have those as well.

@leigero said: Okay. I tried that, but I got the:

“IllegalStateException: Only mono audio is supported for positional audio nodes”

error so I guess I need to use different audio files? I’m not an audio guru or anything but thanks for the tip. As far as updating the listener you’re referring to the location and rotation updates in the simpleInitUpdate methjod? I have those as well.

Only mono sounds is supported for positional audio since stereo already has position in it.

If you mean that in simplerInitUpdate() you are updating a Listener object, then yes… that’s what I’m referring to.

Thanks a ton. Getting proper single channel audio fixed it.