Game Development Community

Swimming

by Skylar Kelty · in Torque Game Engine · 05/09/2006 (7:56 am) · 8 replies

For this resource:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348

Should void Player::pickActionAnimation() look like this?
void Player::pickActionAnimation()
{


   bool forward = true;
   U32 action = PlayerData::RootAnim;

   if (getPlayerPosition() == 1) {

   ////////// enclosing original code in my own stuff

      // Only select animations in our normal move state.
   if (mState != MoveState || mDamageState != Enabled)
      return;

   if (isMounted())
   {
      // Go into root position unless something was set explicitly
      // from a script.
      if (mActionAnimation.action != PlayerData::RootAnim &&
          mActionAnimation.action < PlayerData::NumTableActionAnims)
         setActionThread(PlayerData::RootAnim,true,false,false);
      return;
   }

   ///////// End of original code

   }
   // Swim code, Position code
   else if (getPlayerPosition() == 2) {
	   action = (mVelocity.len() < 0.5) ? PlayerData::CrouchRootAnim : PlayerData::CrouchForwardAnim;
   }
   else if (getPlayerPosition() == 3) {
	   action = (mVelocity.len() < 0.5) ? PlayerData::CrawlRootAnim : PlayerData::CrawlForwardAnim;
	   if (mWaterCoverage != 0.0f) {
		   action = (mVelocity.len() < 0.5) ? PlayerData::SwimRootAnim : PlayerData::SwimAnim;
	   }
   }

Thanks in advance

#1
05/13/2006 (2:52 am)
*bump*
#2
05/13/2006 (5:43 am)
void Player::pickActionAnimation()
{
   // Only select animations in our normal move state.
   if (mState != MoveState || mDamageState != Enabled)
      return;

   if (isMounted())
   {
      // Go into root position unless something was set explicitly
      // from a script.
      if (mActionAnimation.action != PlayerData::RootAnim &&
          mActionAnimation.action < PlayerData::NumTableActionAnims)
         setActionThread(PlayerData::RootAnim,true,false,false);
      return;
   }

   bool forward = true;
   U32 action = PlayerData::RootAnim;

   if (getPlayerPosition() == 1) {
   }
   // Swim code, Position code
   else if (getPlayerPosition() == 2) {
	   action = (mVelocity.len() < 0.5) ? PlayerData::CrouchRootAnim : PlayerData::CrouchForwardAnim;

   }

   else if (getPlayerPosition() == 3) {
	   action = (mVelocity.len() < 0.5) ? PlayerData::CrawlRootAnim : PlayerData::CrawlForwardAnim;
	   if (mWaterCoverage != 0.0f) {
		   action = (mVelocity.len() < 0.5) ? PlayerData::SwimRootAnim : PlayerData::SwimAnim;
	   }
   }

   if (mFalling)
   {
      // Not in contact with any surface and falling
      action = PlayerData::FallAnim;
   }
   else
   {
      if (mContactTimer >= sContactTickTime) {
         // Nothing under our feet
         action = PlayerData::RootAnim;
      }
      else
      {
         // Our feet are on something
         // Pick animation that is the best fit for our current velocity.
         // Assumes that root is the first animation in the list.
         F32 curMax = 0.1;
         VectorF vel;
         mWorldToObj.mulV(mVelocity,&vel);
         for (U32 i = 1; i < PlayerData::NumMoveActionAnims; i++)
         {
            PlayerData::ActionAnimation &anim = mDataBlock->actionList[i];
            if (anim.sequence != -1 && anim.speed) {
               F32 d = mDot(vel, anim.dir);
               if (d > curMax)
               {
                  curMax = d;
                  action = i;
                  forward = true;
               }
               else
               {
                  // Special case, re-use slide left animation to slide right
                  if (i == PlayerData::SideLeftAnim && -d > curMax)
                  {
                     curMax = -d;
                     action = i;
                     forward = false;
                  }
               }
            }
         }
      }
   }
   setActionThread(action,forward,false,false);
}
#3
05/13/2006 (7:29 am)
Thanks
#4
05/13/2006 (7:30 am)
My next problem:
Player won't change postitions by 'c' or by walking into water
I have everything in the resource in the game, I think and I have deleted dso's
#5
05/13/2006 (8:31 am)
It could be any number of things. Double check the head code, check your animations within your model. Also take note of the fact that if you don't delete config.cs new keybindings won't take effect.
#6
05/14/2006 (11:38 am)
The prone and swim animations are not working but I can get crouch working now :)
#7
05/16/2006 (7:49 am)
Anyone? Why won't swim work? Can't find anything :( the player just stands and slides along the water
#8
05/16/2006 (7:57 am)
If your player just stands and slides along the water, you probably have trouble with one of your animations. When he "just stands" - is that equal to him running the root animation? Or is he just still and not moving at all?

If the latter, then you got a problem in your animation. If the former, there's a code problem in pickActionAnimation.