Game Development Community

How to make AIPlayer do turn animation?

by Sibsan Suksuchano · in Torque 3D Professional · 09/14/2010 (2:59 pm) · 3 replies

T3D Beta 2
I've try to make Player to do turn animation by use "delta.rotVec.z" to check that my player is turning or not ,everthing work fine but when I add AIPlayer and set them to run follow path they don't do turn animation.

Anybody have a clue?

some info while player play turning animation they still moving not stop and turn.

If I change AIPlayer to AIClient will it fix this problem?

#1
09/14/2010 (6:25 pm)
AIs have a rotation (z rotation),based on their aim location.
So a possible issue is when you set a rotation,then this value is replaced with a new one.
Well,you can change this situation in AIplayer::getAIMove() and provide your own logic there, thus you can directly play your animation with setActionThread().
#2
09/14/2010 (10:02 pm)
Sibsan,

in player.cpp find:
{ "side", { -1.0f, 0.0f, 0.0f } },       // SideLeftAnim,
and below it add this:
{ "turn", { -1.0f, 0.0f, 0.0f } },      // TurnAnim

then still in player.cpp, find this block of code:
for (U32 i = 1; i < PlayerData::NumMoveActionAnims; i++)
         {
            PlayerData::ActionAnimation &anim = mDataBlock->actionList[i];
            if (anim.sequence != -1 && anim.speed) 
            {
               // We bias towards picking the forward/backward anims over
               // the side to prevent oscillation between anims.  This seems 
               // to work ok but the real fix is to have 8 way directional 
               // animations.
               VectorF biasedDir = anim.dir * VectorF(0.5f,1.0f,0.5f);
               F32 d = mDot(vel, biasedDir);
               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;
                  }
               }
            }
and replace it with this:
/////////////////////// DS turn anim begin //////////////////////////////////////
    if ( mFabs( vel.x + vel.y ) < 0.25 )
     {
      // And we're turning
      if ( delta.rotVec.z != 0 )
     { 

      // Let's sidestep to look like we're turning
      action = PlayerData::TurnAnim; 
      forward = true;

      // If we're turning right animate the other way
     if ( delta.rotVec.z < 0 ) 
        forward = false;
        }
       }
         else // Continue on as normal if we're moving
        {
      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;
          }
         }
        }
       }
/////////////////////// DS turn anim end //////////////////////////////////////

now in player.h, find
SideLeftAnim,
and below it, add:
TurnAnim,   // TurnAnim

rebuild your project,

having done that, open gideon.cs, or whatever your player, or aiPlayer is, and add this:
sequence45 = "./player_turnanim.dsq turn";
under this:
sequence44 = "./player_swimsiderg.dsq swim_right";

now you will need a turn animation,
thats for you to do,

to test it,

copy the crouch animation
and rename it to "player_turnanim.dsq",
and place it in the proper folder,
now when you or whoever else has the turn animation,
they/ you will crouch when turning.

#3
09/15/2010 (4:11 am)
@deepscratch infact I've used your code with comment out mfabs vel.x and vel.y to make player turn even he run.
After test and test I found the problem.In normaly player and AI animation go fine until I have applyImpulse to AI then the delta.rotVec in client side go to 0 only the serverside update.
Any idea?