How to play a spatial sound and then kill it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gokudomatic2
:warning: Old Version Published before Godot 3 was released.

Let’s take a concret example. I’ve a FPS game where the player shoots laser beams (slow, with a begin and an end like in star wars). This projectile eventually hits a wall and then make a sound when it disappears.

Written like that, that seems easy to do. But technically in Godot, it’s far from obvious.
I have to use a SpatialSamplePlayer because it must be played at the collision point. It cannot be part of the projectile node because this node is being queue_freed when the sound starts to play (and the player wouldn’t hear anything).

Then I try to create a SpatialSamplePlayer in the global scene and move it to the collision point. However I don’t know when the sample is done playing. There’s no signal and no option to know the length of the current sample. About the object Sample, there is a get_length method but it gives a number, without unit, that makes no sense. The online documentation says to multiply or divide by two, depending on the format, but that doesn’t give me the real length of the sample.

Does someone know how to play a spatial sound and simply kill it when it’s done?

I didn’t messed with audio yet, but as far as I understand, you play(String sample, int voice) it, where sample is your audio, and voice is the position in the internal array. To check if it’s going, you use is_voice_active(int voice) and to stop it use stop_voice(int voice). I’m not sure though, so I’m keeping this as a comment until you confirm it.

mateusak | 2016-08-01 22:38