Game Development Community

T3D 1.1 Beta 3 - AIPlayer yawing Problem

by Enel · in Torque 3D Professional · 11/04/2010 (5:36 am) · 5 replies

sorry i dont know it is bug or not.. but plz check it T3D client..



Front Player is AIPlayer Class and just Yawing Left

void AIPlayer::updateMove(const Move* move)
{
    if (!getControllingClient() && isGhost())
      return;

    const_cast<Move*>(move)->yaw = -0.05;

    Parent::updateMove(move);
}

but AIPlyaer turning isnt smooth

when AIPlayer turn to next yaw from 0� to 2�. AIPlayer turn around opposite radius and go to right turn.

im so sry to you my bad English.. :(

plz see that video and help me plz..

#1
11/04/2010 (5:55 am)
Use mRot.z instead of move->yaw
The input data is used to be read in the player class.

Then constrain the value to 0 - M_2PI_F

// constrain the range of mRot.z
while (mRot.z < 0.0f)
mRot.z += M_2PI_F;
while (mRot.z > M_2PI_F)
mRot.z -= M_2PI_F;
#2
11/04/2010 (6:27 am)
Point3F CurrentRot = getRotation();

   F64 RotCheak = BotDestRotation.z - CurrentRot.z;

   while (RotCheak < 0.0f)
	   RotCheak += M_2PI_F;
   while (RotCheak > M_2PI_F)
	   RotCheak -= M_2PI_F;

   Con::printf("PlayerRot : %f",CurrentRot.z);

   if(RotCheak <= M_PI_F && RotCheak != 0)
   {
	   RotState = 1; // Right
   }
   else if (RotCheak > M_PI_F && RotCheak != 0)
   {
	   RotState = 2; // left
   }

   if(RotState == 1) // right
   {
	   if(RotCheak <= 0.5)
	   {
		   mRot.z += BotDestRotation.z - CurrentRot.z;
		   RotState = 0;
	   }
	   else
		   mRot.z += 0.5;
   }
   else if(RotState == 2) // left
   {
	   if(RotCheak <= 0.5)
	   {
		   mRot.z += BotDestRotation.z - CurrentRot.z;
		   RotState = 0;
	   }
	   else
		   mRot.z -= 0.5;
   }

   while (mRot.z < 0.0f)
	   mRot.z += M_2PI_F;
   while (mRot.z > M_2PI_F)
	   mRot.z -= M_2PI_F;

i should do this but that bug still work..

anyone has know this problem?
#3
11/04/2010 (7:42 am)
P.S First Rotation works fine but than more rotation has problem..
#4
11/04/2010 (6:58 pm)
This is a bad idea,because you rotate fast (+-0.5) and 6.28 can be passed easily,then you'll move to the opposite rotation.

Try rotating untill BotDestRotation is reached.Use a rotational tolerance or try stepping one tick ahead.

The second approach could be a linear interpolation between BotDestRotation and the current mRot.

F32 angle = mRot.z - BotDestRotation ;	
F32 speed1 = 0.95f;
F32 speed2 = 1 - speed1;
if(angle > M_PI || angle < -M_PI) mRot.z = (mRot.z*speed1) + (BotDestRotation + M_2PI) * speed2 ;
else  mRot.z = (mRot.z * speed1) + (BotDestRotation  * speed2 );
#5
11/05/2010 (12:43 am)
thank you for your advice :) im apply your code

but i think it is RenderProblem.. so where i cant find code :(..