Game Development Community

HoverVehicle AI Movement...

by Daniel M. Clark · in General Discussion · 04/20/2003 (11:53 pm) · 5 replies

Ok people, Lots of rewriting took place in order to get to this to work. You have to add a few lines to GetTick, and you have to change the inheritance of AIPlayer to the HoverVehicle class...

Here is What I did to AIMove to get to the HoverCars Rotating to the Move Destination and Moving (extremely eugly, ill explain later) to the desired Destination.

AIPlayer.cc:

bool AIPlayer::getAIMoveV(Move *movePtr)
{
*movePtr = NullMove;

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

F32 xDiffPos = mMoveDestination.x - location.x;
F32 yDiffPos = mMoveDestination.y - location.y;

// Move towards the destination
if (mMoveState == ModeMove)
{
// Check if we should mMove, or if we are 'close enough'
if (mFabs(xDiffPos) < mMoveTolerance && mFabs(yDiffPos) < mMoveTolerance)
{
mMoveState = ModeStop;
mSteering.x = 0;
mSteering.y = 0;
throwCallback("onReachDestination");
}
else
{

MatrixF eye;
Point3F forward;
Point3F up(0.0, 0.0, 1.0);
Point3F right;
Point3F targettoai;

// Get the AI's transform.
eye = getTransform();

// Get the AI's eye vector and normalize it.
eye.getColumn(1, &forward);
forward.normalize();

// Get the right vector.
mCross( forward, up, right );
right.normalize();

// Get the Target to AI vector and normalize it.
targettoai = mMoveDestination - location;
targettoai.normalize();

F32 dot = mDot( right, targettoai );

// Con::errorf(ConsoleLogEntry::General, "dot: %f", dot );

if( dot > 0.1f )
{
movePtr->yaw = 0.2f;
}
else if( dot < -0.1f )
{
movePtr->yaw = -0.2f;
}
else
{
mSteering.x = 0;
mSteering.y = 0;
}

// This should be all that is needed to move the vehicle forward.
// movePtr->y = 0.4f;

double dist = ((mMoveDestination.x - location.x)*(mMoveDestination.x - location.x))+
((mMoveDestination.y - location.y)*(mMoveDestination.y - location.y))+
((mMoveDestination.z - location.z)*(mMoveDestination.z - location.z));

if(dist > 100)
// Adjust speed
movePtr->y = .2;
else
movePtr->y = .002;

}
}

// Replicate the trigger state into the move so that
// triggers can be controlled from scripts.
for( int i = 0; i < MaxTriggerKeys; i++ )
movePtr->trigger[i] = getImageTriggerState(i);

return true;
}

AIPlayer.h:

MatrixF mMat;
Point3F mRot;
Point3F& getRotation()
{
mMat = getTransform();
mMat.getColumn(1, &mRot);
mRot.normalize();
return mRot;
}

Now the only Fudged up part about this is, when the HoverCar tries to move to the Destination his Thrust action is all wierded out. He moves in one direction, and kinda keeps going back and forth. He never really gets to the destination. I cant figure that part out yet...
But he is always perfectly rotated towards the destination. go figure..

Anyways, I hope you guys can get in on this and help me figure out the rest.

Thanks,

J

#1
04/28/2003 (4:01 pm)
ok.. so.. u have to increase "mMoveTolerance" !! i set it to about 7.5


Im still trying to get the Pitch working.. ugh..

any help would be great .. thanks..


also.. for some reason my Bots wont hit the Target!!
Ive made it so they can only rotate.. no movement.. same for the player..

Its strange.. im using this for the aim target ( LocalClientConnection.player.getWorldBoxCenter() )

but its still shooting right next to the player!!

Im guessing thats not getting the center of the player..
#2
07/27/2003 (10:56 pm)
Daniel,
Thanks for the post, there are not many sources of information for AI Vehicles. I'm trying to get a simple racing game together, and cannott get this code to work properly. I'm getting undeclared identifier problems which is do to not inheriting the WheeledVehicle class. When I try to inherit the class, it gives me an error saying that the base class is undefined. If it is not too much trouble, could you show me how you implemented inheritance in your code? Also, I was wondering what you added to GetTick, although it doesn't matter since the function is nowhere to be found. Any help would be greatly appreciated.

Thanks,
Beau Clark
#3
07/28/2003 (9:01 am)
Guys, torque specific stuff should go in the appropriate forums, and in the private ones, when there is C++ code.
#4
07/28/2003 (10:12 am)
Niclolas,
I had already created a thread in the appropriate forum, but after getting no response, I decided to post elsewhere. As for the C++ code, unless you own the SDK, the information is of little use.

Beau
#5
07/28/2003 (12:33 pm)
Nick is right.

Discussion of Torque-specific C++ or ASM code goes in the private forums. If you want, make a link from here to a post in the private forums... or post the code as a resource.