Game Development Community

Oh goodie, another question about looping gun sounds

by Bryce · in Torque Game Engine · 07/05/2010 (4:22 am) · 5 replies

Hey kids

To avoid the infamous fire sound stutter on fast-firing weapons, I use a continuous looping sound for the shots. As long as the mouse button is held, the looping sound will continue playing. My issue is that if you press the trigger fast enough (trying to squeeze off just one shot), the sound will cut off, playing only part of the sound or complete silence. This is because the Torque only plays the looping fire sound while in the weapon's "Fire" state, and is cancelled upon entering another state, in this case it's "Ready".

What I'm looking for is a way to ensure that the fire loop will play at least once. Meaning, instead of just abruptly cutting off the sound when the state is switched, the engine should just stop it from looping again. Hope I'm being clear enough, help is appreciated as always!

Thanks,
Bryce

#1
07/05/2010 (6:45 am)
Don't use the weapon states.

function LMB_Pressed(%val)
{
   if (%val)
   {
      // play looping fire sound
   }
   else
   {
      // stop looping fire sound
   }
}
#2
07/05/2010 (6:50 am)
Not exactly what I'm looking for. That doesn't really take into account what the weapon is doing, what weapon you are currently using, etc.

I just want a way to tell the engine "we stopped shooting, finish playing the sound, but don't loop it again", somewhere within the depths of the image state code.
#3
07/05/2010 (7:29 am)
You can measure the time between mouse press and mouse release.

function StopTheWeaponSound()
{
   alxStop(someSound);
}


%measuredTime = 25000; // ms 
%lengthOfSound = 135; // ms
%gap = %measuredTime % %lengthOfSound; // modulo

%waitTime = %lengthOfSound - %gap;

schedule(%waitTime, 0, stopTheWeaponSound);

In other words: Calculate the remaining time to play the whole last loop. Then stop the sound.
#4
07/14/2010 (12:04 am)
How about adding sound to the ready state, to finish off the firing sound?

Alternatively, I'd agree with Thomas that you shouldn't use the image state machine to deal with sounds. Either some sort of separate sound state system within the image class, or a separately mounted image that deals with the sounds... I wish I could be more helpful :P.
#5
07/14/2010 (12:13 am)
I ended up adding an "endfire" state that happens when the trigger is released, which plays a shot falloff sound before returning to the ready state. Sounds good enough for me, certainly not anything catastrophic to the gameplay. The ideas are helpful, I'll look into ditching the stock state machine. Thank you!