aiplayer and stuck
by Jeff "tubaguy" Vance · in Torque Game Engine · 09/18/2002 (6:06 pm) · 1 replies
I've been fiddling around with the bots and have made a couple changes that seem to make it work better. I'm very new to the C++ world, so I'd like some opinions.
First, I changed the location of the callback for ReachDestination so the callback fires after the movestate changes. This allowed me to set a new move directly in the callback.
// Check if we should mMove, or if we are 'close enough'
if (mFabs(xDiff) < mMoveTolerance && mFabs(yDiff) < mMoveTolerance) {
mMoveState = ModeStop;
throwCallback("onReachDestination");
Second, I played a bit with the Stuck check. It seems that x and yDiff are finished by this point so I reused them to calculate the difference between the current and last move. A range check scaled for the ai move speed then will fire the callback.
// We should check to see if we are stuck.
xDiff=mFabs(mLastLocation.x - location.x) / mMoveSpeed;
yDiff=mFabs(mLastLocation.y - location.y) / mMoveSpeed;
if ((xDiff < 0.01) && (yDiff < 0.01)) {
throwCallback("onMoveStuck");
mMoveState = ModeStop;
}
mLastLocation=location;
Good, bad or ugly?
tubs
First, I changed the location of the callback for ReachDestination so the callback fires after the movestate changes. This allowed me to set a new move directly in the callback.
// Check if we should mMove, or if we are 'close enough'
if (mFabs(xDiff) < mMoveTolerance && mFabs(yDiff) < mMoveTolerance) {
mMoveState = ModeStop;
throwCallback("onReachDestination");
Second, I played a bit with the Stuck check. It seems that x and yDiff are finished by this point so I reused them to calculate the difference between the current and last move. A range check scaled for the ai move speed then will fire the callback.
// We should check to see if we are stuck.
xDiff=mFabs(mLastLocation.x - location.x) / mMoveSpeed;
yDiff=mFabs(mLastLocation.y - location.y) / mMoveSpeed;
if ((xDiff < 0.01) && (yDiff < 0.01)) {
throwCallback("onMoveStuck");
mMoveState = ModeStop;
}
mLastLocation=location;
Good, bad or ugly?
tubs
Torque Owner Paul Scott
Default Studio Name
to match what is in aiPlayer.cs