Game Development Community

Aiplayer yaw & pitch orientation

by Luis Anton · in Torque Game Engine · 05/10/2004 (4:08 am) · 5 replies

Hi!
I'm quite confused with the bots orientation code in AIPlayer.cc. I want them not only to yaw (they already do that properly) but also to pitch towards the moveDestination point.
I changed the pitch code in aiplayer.cc, in getAIMove, which seemed to deal just with head movement, with this:

// use the cur pitch between -Pi and Pi
F32 curpitch = rotation.x;

while (curpitch > M_2PI)
   curpitch -= M_2PI;

   while (curpitch < -M_2PI)
      curpitch += M_2PI;

   // find the pitch offset
   F32 newpitch = -mAtan(zDiff, mSqrt(xDiff*xDiff + Diff*yDiff));
   F32 pitchDiff = newpitch - curpitch;

   // make it between 0 and 2PI
   if( pitchDiff < 0.0f )
     pitchDiff += M_2PI;
   else if( pitchDiff >= M_2PI )
     pitchDiff -= M_2PI;

   // now make sure we take the short way around the circle
   if( pitchDiff > M_PI )
      pitchDiff -= M_2PI;
   else if( pitchDiff < -M_PI )
      pitchDiff += M_2PI;

   movePtr->pitch = pitchDiff;

which is the almost the same as the yaw code, but changing the aTan operation.

It doesn't work, there's no pitch in my bots :( Am I being too naive? Is it much more complex than that?

#1
05/11/2004 (3:11 am)
Well, I also found in player.cc that only z rotations are taken into account (or at least it seems that way...)

so I changed, in
void Player::setTransform(const MatrixF& mat)

this line
Point3F rot(0, 0,-mAtan(-vec.x,vec.y));

with this one:
Point3F rot(-mAtan(vec.z, mSqrt(vec.x*vec.x + vec.y*vec.y)),0,-mAtan(-vec.x,vec.y));

and in
void Player::setPosition(const Point3F& pos,const Point3F& rot)

this line
mat.set(EulerF(0, 0, rot.z));

with this one
mat.set(EulerF(rot.x, 0, rot.z));

but it's the same: nothing, zero, no pitch, no effect at all. The effect should be quite simple: when following a path, aiplayers should face directly to the next node, not only yawing but also pitching... am I missing something? (probably, but what?)
#2
05/11/2004 (3:44 am)
Might need to look further back in the chain.. If I recall correctly the z rot is squashed earlier in the process, before it gets to the AIPlayer/Player functions.

-Ron
#3
05/11/2004 (5:33 am)
Back? But it's in AIPlayer where bots orient themselves towards their destination point... where could it be? Shapebase or something? It's only players who stand up and don't pitch, isn't it? Cameras can yaw and pitch, and also vehicles... I'll dig there a little bit... look for "(0, 0," in the code, or something :)
#4
07/05/2004 (7:28 pm)
Careful. Rotation.z means "rotation about z-axis" meaning rotation in x,y meaning YAW. Don't let that throw you

I'm working on this, and I've got it working .. MOSTLY. Right now I'm trying to get AIFlyingVehicles to do this part.

From my research, it seems to store the pitch and yaw in the rotation (head rotation) PLUS in the move structure (moveptr->yaw) and both are used when it goes to turn the player object towards its destination.

The odd thing about the code I've got working is that there is a slight error that gets worse the furhter away your waypoint(aim) is.. Also, in my code, I can't detect hit on a waypoint in height but still only in x,y.

The ways of x,y,z in the code are baffling and mysterious. When I created a zDiff to the check for waypoint-arrival, the sub spun merrily in place forever.. (example)
#5
08/21/2006 (9:15 am)
I know this thread is two years old, but I could use the solution if anyone has found it.

Has anyone figured out a way to make AIPlayer pitch towards the destination?
Currently, the head pitches to face the target.. is there a way to set it such that the entire body pitches towards the target location?