0 votes

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?

in Engine by (698 points)

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.