Game Development Community

Mounted AI aim bug

by Vincent D · in Torque Game Engine · 02/08/2007 (1:30 am) · 3 replies

Hello, ive ran into this 'small' problem. The AI aim works great but not when the bot is mounted to a vehicle. The bot will aim at the proper position at first but as soon as the vehicle starts to move (and turn) the bots will still try to aim but it wont adjust to how the vehicle is turning. How would i fix this?

thanks in advance, Vincent

#1
02/08/2007 (7:17 am)
Sounds like the bot uses its local rotation transformation for calculation instead of the global one, so it ignores the one of the vehicle which causes this error.

I've 2 ideas for ways to come around:

Idea 1: For the lazy ones. Unmount - Aim - Remount at the appropriate place.


Idea 2: Changing the calculation and make it use the global transformation instead of the local one, that way it would work with mounted and unmounted, not only with unmounted.
#2
02/08/2007 (7:46 am)
Hmmm so i found in bool AIPlayer::getAIMove(Move *movePtr)

// Use the eye as the current position.
   MatrixF eye;
   getEyeTransform(&eye);
   Point3F location = eye.getPosition();
   Point3F rotation = getRotation();

I guess this is the problem? how would i get the world rotation/transform?

EDIT:

I think Point3F rotation = getRotation() should be something like Point3F rotation = eye.getRotation() what doesnt exist. So I need to find another way of getting the rotation out of the matrix but have no idea how (yet). So now im trying to get a better understanding of matrixes.

i would still like if someone helped me out hehe
#3
02/08/2007 (1:23 pm)
Ok i fixed it

I moved the extractEuler method from worldeditor.cc to mMatrix.cc and changed it like so
EulerF MatrixF::extractEuler() const
   {
      //const F32 * mat = (const F32*)matrix;
	  const F32 * mat = m;

      EulerF r;
      r.x = mAsin(mat[MatrixF::idx(2,1)]);

      if(mCos(r.x) != 0.f)
      {
         r.y = mAtan(-mat[MatrixF::idx(2,0)], mat[MatrixF::idx(2,2)]);
         r.z = mAtan(-mat[MatrixF::idx(0,1)], mat[MatrixF::idx(1,1)]);
      }
      else
      {
         r.y = 0.f;
         r.z = mAtan(mat[MatrixF::idx(1,0)], mat[MatrixF::idx(0,0)]);
      }

      return(r);
   }

Then i putted the following at line 131 in mMatrix.h bellow Point3F getPosition() const;
/// extract the rotation aspect of this matrix as eulers.   
   EulerF    extractEuler() const;

then in worldeditor.cc change
mHitRotation = extractEuler(mSelected[0]->getTransform());
to
mHitRotation = mSelected[0]->getTransform().extractEuler();
and do the same for the other places where extractEuler is used (put the arguments before extractEuler and add an dot.)

now in AIplayer.cc change the following in bool AIPlayer::getAIMove(Move *movePtr)
from
// Use the eye as the current position.
   MatrixF eye;
   getEyeTransform(&eye);
   Point3F location = eye.getPosition();
   Point3F rotation = getRotation();
to
// Use the eye as the current position.
   MatrixF eye;
   getEyeTransform(&eye);
   Point3F location = eye.getPosition();
   Point3F rotation = eye.extractEuler();
   //Point3F rotation = getRotation();

that should fix it and if not then ive forgot something.

edit: small typo