Game Development Community

Step sounds, recoil and hit scans.

by Danni · 05/04/2008 (3:42 pm) · 5 comments

www.antihax.net/movies/swheet.jpg
Strange oddity, when connected to a dedicated server the players footsteps sound behind him. Actually if I swing sharply 90 degrees you can hear the step on the left or right. Very scary! Digging deeper it seams the Source for the sound is not moved once it starts playing. So with a few modifications based on the imageSound method and our players footsteps sound just a little bit better.


void Player::playFootstepSound(bool triggeredLeft, S32 sound)
{
   const Point3F& velocity  = getVelocity();
   const MatrixF footMat	= getRenderTransform();
   const SFXProfile * soundProfile = mDataBlock->sound[PlayerData::FootHard];
   if ( mWaterCoverage == 0.0f )
   {
      switch ( sound )
      {
         case 0: // Soft
            soundProfile = mDataBlock->sound[PlayerData::FootSoft];
            break;
         case 1: // Hard
            soundProfile = mDataBlock->sound[PlayerData::FootHard];
            break;
     ...
      }
   }
   else
   {
      if ( mWaterCoverage < mDataBlock->footSplashHeight )
         soundProfile = mDataBlock->sound[PlayerData::FootShallowSplash];
      else
      {
         if ( mWaterCoverage < 1.0 )
            soundProfile = mDataBlock->sound[PlayerData::FootWading];
         else
         {
            if ( triggeredLeft )
            {
               soundProfile = mDataBlock->sound[PlayerData::FootUnderWater];
               SFX->playOnce( mDataBlock->sound[PlayerData::FootBubbles], &footMat, &velocity );
            }
			else
			{
				soundProfile = NULL;
			}
         }
      }
   }
	   
   if (soundProfile)
   {
	  stepSound = SFX->createSource( soundProfile, &footMat, &velocity );

      // If we have the source... play it.
      if ( stepSound )
	     stepSound->play();
   }
}

void Player::advanceTime(F32 dt)
{
......

   // Update any playing sound.
   if ( stepSound )
   {
      stepSound->setTransform( getRenderTransform() );
      stepSound->setVelocity( getVelocity() );

   }
......
}

Plodding along, the hit scan system is working just dandy! The game client performs a hitscan when the trigger is pulled displaying nice Explosion effects for bullet impacts, the server replicates the hitscan and deals the real damage. Checkout www.antihax.net/movies/pwntfx.wmv

I also managed to get a basic client side recoil effect in there, although i need to smooth the effect out. It is a bit sudden.

#1
05/04/2008 (3:46 pm)
How did you get projectile splashes working? Can you post your splash datablocks? I love the video, great work.
#2
05/04/2008 (3:53 pm)
Thats a bit complicated. I added a ballisticExplosion and method to each class that could be impacted (Interior, StaticShape, Player, etc). Then in the game editor I can set the objects Explosion (Dirt Puff, Water Splash, Metal Spark, etc). Then my handy dandy shared scripts do the rest thus this won't work in Stock Torque.

Also i see i misread your comment. I do not use projectiles, I use hitscans aka raycasts.
function m16Image::onFire(%this, %obj, %slot)
{
	  if (!Parent::onFire(%this, %obj, %slot))
		   return false;

	  if (!%obj.isServerObject() && %obj.isControllingClient()) 
		   %this.doRecoil();
 
    %searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::StaticObjectType | $TypeMasks::AtlasObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::WaterObjectType | $TypeMasks::VehicleObjectType | $TypeMasks::VehicleBlockerObjectType | $TypeMasks::CorpseObjectType | $TypeMasks::DebrisObjectType | $TypeMasks::AIObjectType; 

    %damage = 60;
    %muzzzleVector = %obj.getMuzzleVector(%slot);
    %muzzzleVector = VectorNormalize(%muzzzleVector);
    %yaw   = YawFromVector(%muzzzleVector);
    %pitch = PitchFromVector(%muzzzleVector);
    %yaw   += mDegToRad(((((%obj.getRandom()-128) << 10) / 65536.0)/65536.0)*360);
    %pitch += mDegToRad(((((%obj.getRandom()-128) << 10) / 65536.0)/65536.0)*360);
    %muzzzleVector = VectorFromAngles(%yaw, %pitch);
    %muzzzleVector = VectorScale(%muzzzleVector, 10000);
    %muzzlePoint = %obj.getMuzzlePoint(%slot); 
    %distance = VectorAdd(%muzzlePoint, %muzzzleVector);

    // Do a "hitscan"
    %scanTarg = ContainerRayCast(%muzzlePoint, %distance, %searchMasks, %obj); 
    if(%scanTarg) 
    { 
		  if (%obj.isServerObject())
		  {
  			%target = firstWord(%scanTarg);
	  		%target.damage(%obj,%pos,%damage,%this.meansOfDeath);
		  }
		  else
		  {
	        %target = firstWord(%scanTarg);
	        %pos = getWords(%scanTarg, 1, 3);
		      [b]%target.ballisticExplosion(%pos, "1 1 1");[/b]
		  }
    }
}
#3
05/05/2008 (1:46 am)
So the first snippet makes the sound emitters follow the player?
#4
05/05/2008 (2:04 am)
Exactly! There are a few other standard requirements, but that's the meat.
#5
05/05/2008 (4:03 am)
Nice I always thought the step sounds should follow the player in some situations... It really depends on how fast the player moves and how long the step sounds are really.

If the step sounds are really basic (e.g. just the clop of a foot and NOT a detailed 500ms-1s long sound with clothing movement and terrain debris details) then this way of the emitter following the player is great...

If you have really detailed sounds as described above, the sounds staying where they emitted is a better fit because (typically) the movement and clop of the foot is in the first 100-150ms of the sound and the the terrain debris details are in the next 3-400ms or so. The terrain debris sound in the real world would probably make the sound WHERE you stepped so it makes more sense. The HRTF takes care of the rest of the perceptive location.


Now here is where this would come in handy, try the moving with the player code with the gun shots, reloading sounds, activating sounds etc.. It makes total sense in games that only use 3D emitters for the 1st person sounds and observers or 3rd person sound.

Another option is to play a 2d sound stereo or mono that plays for the player only and other players in the game hear a 3d emitter version (not the player) This system works well for gun sounds.