Game Development Community

Crouch and Prone Side Back Animations

by Steve Acaster · in Torque 3D Professional · 10/16/2009 (11:59 am) · 6 replies

Disclaimer:
I am not a programmer. This might be great WIN - or it might be a great HACK. It's the first time I've ever coded anything that not only compiled but also appears to work in-game as it should.

IN YOUR FACE HUMANITY!
erm ... sorry ... momentarily crazed with power there ...

Crouch_Side, Crouch_Back, Prone_Back, Prone_Side animations

[Update] 20thOct09
Just changed a few things, added the rest of the missing prone animations, allowed sideways movement when prone, cleaned up the code, got the keybinds working better, and jumping now cancels crouch/prone.

Player.ccp, Around line 129
PlayerData::ActionAnimationDef PlayerData::ActionAnimationList[NumTableActionAnims] =
{ "crouch_root" },
   { "crouch_forward" },
   { "crouch_back" },//yorks added
   { "crouch_side" },//yorks added
   { "prone_root" },
   { "prone_forward" },
   { "prone_back" },//yorks added
   { "prone_side" },//yorks added
   { "swim_root" },
   { "swim_forward", { 0.0f, 1.0f, 0.0f } },
   { "swim_backward", { 0.0f, -1.0f, 0.0f } },
   { "swim_left", { -1.0f, 0.0f, 0.0f } },
   { "swim_right", { 1.0f, 0.0f, 0.0f } },

PlayerData::PlayerData() Around Line 214 - Change velocity to allow prone sideways movement
// Prone
   proneForce = 45.0f * 9.0f;            
   maxProneForwardSpeed = 2.0f;  
   maxProneBackwardSpeed = 2.0f; 
   maxProneSideSpeed = 1.0f;//yorks - was 0.0f

void Player::pickActionAnimation() Vaguely Around line 2954
if ( vel.y > 0.1f )
      {
         action = PlayerData::CrouchForwardAnim;
         forward = true;
      }
      else if ( vel.y < -0.1f )
      {
         action = PlayerData::CrouchBackAnim;//yorks changed from CrouchForwardAnim
         forward = false;
      }
//yorks added
      if ( vel.x > 0.1f )
      {
         action = PlayerData::CrouchSideAnim;
         forward = true;
      }
      else if ( vel.x < -0.1f )
      {
         action = PlayerData::CrouchSideAnim;
         forward = false;
      }
//yorks end of added
   }
   else if ( mPose == PronePose )
   {
      VectorF vel;
      mWorldToObj.mulV(mVelocity,&vel);

      action = PlayerData::ProneRootAnim;
      fsp = true;

      if ( vel.y > 0.1f )
      {
         action = PlayerData::ProneForwardAnim;
         forward = true;
      }
      else if ( vel.y < -0.1f )
      {
         action = PlayerData::ProneBackAnim;//yorks changed from ProneForwardAnim
         forward = false;
      } 
//yorks added
	   if ( vel.x > 0.1f )
      {
         action = PlayerData::ProneSideAnim;
         forward = true;
      }
      else if ( vel.x < -0.1f )
      {
         action = PlayerData::ProneSideAnim;
         forward = false;
      }
//yorks end of added
   }
   setActionThread(action,forward,false,false,fsp);

Player.h, Around line 183 and then 208
Keep the order as in player.cpp or you'll get the animations mixed in-game
struct PlayerData: public ShapeBaseData {
CrouchRootAnim,
      CrouchForwardAnim,
      CrouchBackAnim,//yorks added
      CrouchSideAnim,//yorks added
      ProneRootAnim,
      ProneForwardAnim,
      ProneBackAnim,//yorks added
      ProneSideAnim,//yorks added
      SwimRootAnim,
      SwimForwardAnim,
      SwimBackwardAnim,
      SwimLeftAnim,
      SwimRightAnim,

// ...........

      // 
      NumMoveActionAnims = SideLeftAnim + 1,
      NumTableActionAnims = JetAnim + 1,

      NumExtraActionAnims = 512 - NumTableActionAnims,
      NumActionAnims = NumTableActionAnims + NumExtraActionAnims,
      ActionAnimBits = 13,//yorks changed from 9
      NullAnimation = (1 << ActionAnimBits) - 1
   };

In scripts/client/default.bind.cs, set both crouch and prone to a toggleable on/off function, so you don't have to keep the button pressed down. Remember to update your config.cs appropriately.
Around line 260
// ----------------------------------------------------------------------------
// Stance/pose
// ----------------------------------------------------------------------------
function doCrouch(%val)  
{  
	if(%val)
	$mvTriggerCount3++;
	$mvTriggerCount4=false;
 }  
 
moveMap.bind(keyboard, c, doCrouch);  //yorks changed
//moveMap.bind(keyboard, x, doCrouch);

function doProne(%val)
{
	if(%val)
	$mvTriggerCount4++;
	$mvTriggerCount3=false;
}

moveMap.bind(keyboard, x, doProne);

And disable crouch/prone with a jump. Handy if you get confused with the keys.
function jump(%val)
{
   $mvTriggerCount2++;
   $mvTriggerCount3=false;   //yorks added
   $mvTriggerCount4=false;   //yorks added
}

It's important to note that the stock AI does NOT have a pose management function, and thus they are likely to default to prone. If a model does not have prone animation, prone will not be available.

[/update]

And that appears to work. Don't foget to update your relative player's dts cs file (under art/shapes/actors in stock T3D)

Phew ... that was stressful

#1
10/16/2009 (12:45 pm)
//yorks crazy but funny

Sweet!
#2
10/16/2009 (1:15 pm)
Nice one Steve. We'll have you programming yet :D
#3
10/16/2009 (1:16 pm)
Come to the dark side of programming :)

www.geekologie.com/2009/05/08/the%20dark%20side.jpg
#4
10/16/2009 (1:44 pm)
Also I've altered the Crouch mode to a super simple on/off rather than having to keep the key pressed down. In key.binds.cs obviously.
function doCrouch(%val)
{
if(%val==1)
	$mvTriggerCount3++;
}
This way might not be best for my plans to sort out a stand, crouch, prone system.

Then again ... if I had a seperate doProne()I could go from prone to crouch, then uncrouch. Maybe ....
#5
10/20/2009 (12:36 pm)
Updated with prone animations and associated keybindings for player functionality.

Now if I can just work out how to make a console method for Player::setPose() and create a Player::getPose and related console method, we could stop the AI from defaulting to prone with a script function call when they spawn, as well as give greater functionality to the AI in-game.

I see a "getPose" in the public section of "player.h" but no related function in "player.cpp".
#6
02/04/2010 (12:20 pm)
Did Prone and Crouch get taken out of the hard coding at some point? I had some contract work done and now the engine seems to be looking for the crouch and prone animations and I can't find find the prone dsq's anywhere. So...I'm getting errors in the console. If anyone has the stock prone animations I could use them!

Thanks!