Game Development Community

Swim Animation is still playing out of water?

by Alex (Stalker) Sakablukow · in Torque Game Engine · 10/30/2006 (12:25 am) · 3 replies

I have added new animations, like 2 run-animations
http://www.garagegames.com/mg/forums/result.thread.php?qt=35333

and swim animations (have 4 of them)
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348

and here is a problem with this animations.. if the player go into the water, he can swim with no problem, the animations are correct, but if he go out from water, the run/root animations are "broken", he try to swim sometime, ir in the root animation seems to be "merged" with the swim animation.. what looks funny, bit is a bug ;P

#1
10/30/2006 (12:25 am)
Here is my pickActionAnimation-function, i think here is the error... or maybe my graphic-artist has exported animations in a wrong way?

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 (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]; // STL [DEF1]
            if (anim.sequence != -1 /*&& anim.speed*/ ) // STL [U1287] checked off anim.speed
			{
               F32 d = mDot(vel, anim.dir);
               if (d > curMax) 
               {
                  curMax = anim.speed; // STL [U1287] checked off- 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;
                  }
               }
            }
         }

         // STL [U1287] add
         //Force the player animation if specified		
				 if (action == PlayerData::RunForwardAnim && mQuickRunMovement)		 			 
					 action = PlayerData::QuickRunAnim;			 		 		 
				  
				 //Select rotation animation
				 if ((mFabs(mRotDirection) > 0.005f) && action == 0) {
					 PlayerData::ActionAnimation &anim = mDataBlock->actionList[PlayerData::RotationAnim];
					 if (anim.sequence != -1)
						 action = PlayerData::RotationAnim;						 
				 }	 
         // STL [U1287] add end  

      }
   }

	 if (getPlayerPosition() == 1) 
	 {   
		////////// enclosing original code in my own stuff      
		///////// 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;	  

			  // STL [U1288] add
				 if (action == PlayerData::SwimAnim && mQuickSwimMovement)		 			 
					 action = PlayerData::QuickSwimAnim;

				 if (action == PlayerData::SwimAnim && mTurboSwimMovement)		 			 
					 action = PlayerData::TurboSwimAnim;
				 // STL [U1288] add end
				 
		 }   
		 else
		 {
			 setPlayerPosition(1);
			 // action = PlayerData::RootAnim;
		 }
	 }

   setActionThread(action,forward,false,false);
}
#2
10/30/2006 (5:17 am)
You need to put some of that code inside the
if (getPlayerPosition() == 1)

Like this:

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){
		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;
								}
							}
						}
					}
				}
			}
		}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;
			}
		}
	setActionThread(action,forward,false,false);
}

btw: That code is just for swimming
#3
10/31/2006 (7:30 am)
Have put the animations into playerposition1-block, but it hasnt do anything.. the animations are broken exactly as before..

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) 
	 {   
		 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]; // STL [DEF1]
							if (anim.sequence != -1 /*&& anim.speed*/ ) // STL [U1287] checked off anim.speed
							{
								 F32 d = mDot(vel, anim.dir);
								 if (d > curMax) 
								 {
										curMax = anim.speed; // STL [U1287] checked off- 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;
										}
								 }
							}
					 }

					 // STL [U1287] add
					 //Force the player animation if specified		
					 if (action == PlayerData::RunForwardAnim && mQuickRunMovement)		 			 
						 action = PlayerData::QuickRunAnim;			 		 		 
					  
					 //Select rotation animation
					 if ((mFabs(mRotDirection) > 0.005f) && action == 0) {
						 PlayerData::ActionAnimation &anim = mDataBlock->actionList[PlayerData::RotationAnim];
						 if (anim.sequence != -1)
							 action = PlayerData::RotationAnim;						 
					 }	 
					 // STL [U1287] add end  

					 if (mWaterCoverage != 0.0f) 
					 {		   
						 action = (mVelocity.len() < 0.5) ? PlayerData::SwimRootAnim : PlayerData::SwimAnim;	  

							// STL [U1288] add
							 if (action == PlayerData::SwimAnim && mQuickSwimMovement)		 			 
								 action = PlayerData::QuickSwimAnim;

							 if (action == PlayerData::SwimAnim && mTurboSwimMovement)		 			 
								 action = PlayerData::TurboSwimAnim;
							 // STL [U1288] add end
							 
					 }   
					 else
					 {
						 setPlayerPosition(1);
						 // action = PlayerData::RootAnim;
					 }
					 // STL [U1288] add
										 // STL [U1288] add end
				}
		 }
		
	 }   
	 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;	   
		 
	 }

   setActionThread(action,forward,false,false);
}