Author Topic: Looping a Sound that Follows the Player  (Read 1060 times)

I'm making a lightsaber. I've got the loop for the hum, but I'm trying to have it play from a function rather than "statesound[1]" so that the loop won't be overridden by "statesound[2]". So far it seems to play the sound when I want it to and the state sounds don't override it, but the sound remains in the same spot that it was played from. I'd like it to follow the player, what would be a good method of doing this?

Code: [Select]
function LightsaberBlueImage::onLoopStart(%this, %obj, %slot)
{
serverPlay3D(SaberLoopSound,%obj.getTransform());
}

Hopefully the solution was right under my nose the whole time.

You'll need a sound that doesn't loop and then you'll need to make it manually loop by repeatedly calling the function. You need to do this because you need to update serverPlay3D with the player's new position.

Use Player::playAudio.

Wouldn't

Code: [Select]
%obj.playHum = true;
schedule(time,0,"lightsaberHum",%obj);

function lightsaberHum(%player) {
if(%player.playHum) {
serverPlay3D(SaberLoopSound,%player.position);
schedule(time,0,"lightsaberHum",%player)
}
}

work as intended as long as the playHum variable is correctly set to true and to false when equipping and unequipping the tool?

Wouldn't

Code: [Select]
%obj.playHum = true;
schedule(time,0,"lightsaberHum",%obj);

function lightsaberHum(%player)
{
    if(%player.playHum)
    {
        serverPlay3D(SaberLoopSound,%player.position);
        schedule(time,0,"lightsaberHum",%player)
    }
}

work as intended as long as the playHum variable is correctly set to true and to false when equipping and unequipping the tool?

pls indent your code properly if you want to help people

Use Player::playAudio.

%player.playAudio(%slot, SaberLoopSound);

%player.playAudio(%slot, SaberLoopSound);
and then to stop, %player.stopAudio(%slot);