Previous Blog Next Blog
Prev/Next Blog
by date

Step sounds, recoil and hit scans.

Step sounds, recoil and hit scans.
Name:Danni 
Date Posted:May 04, 2008
Rating:4.8 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Danni

Blog post


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.

Recent Blog Posts
List:07/17/08 - AFX Selected Objects, AutoAttack AI and Jerkiness.
06/01/08 - Async (non-blocking) Postgres Database Handler
05/18/08 - Postgres as a database solution?
05/04/08 - Step sounds, recoil and hit scans.
01/27/08 - Torque prediction hack for hitscans

Submit ResourceSubmit your own resources!

Adam Beer   (May 04, 2008 at 15:46 GMT)
How did you get projectile splashes working? Can you post your splash datablocks? I love the video, great work.

Danni   (May 04, 2008 at 15:53 GMT)   Resource Rating: 5
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);
%target.ballisticExplosion(%pos, "1 1 1");
}
}
}

Edited on May 04, 2008 15:55 GMT

Ryan Jaeger   (May 05, 2008 at 01:46 GMT)   Resource Rating: 4
So the first snippet makes the sound emitters follow the player?

Danni   (May 05, 2008 at 02:04 GMT)   Resource Rating: 5
Exactly! There are a few other standard requirements, but that's the meat.

Ryan Jaeger   (May 05, 2008 at 04:03 GMT)   Resource Rating: 4
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.

You must be a member and be logged in to either append comments or rate this resource.