Game Development Community

[Bug] onMoveStuck not working [with Fix] aka onStuck - RESOLVED

by George Anderson · in Torque 3D Professional · 05/05/2010 (11:23 pm) · 4 replies

File aiPlayer.cpp

Function:
bool AIPlayer::getAIMove(Move *movePtr)

The onMoveStuck throwback never got triggered because mLastLocation wasn't defined. Then after defining it, when it did work It only worked if the bot was perfectly still which never happens.
Then mMoveState = ModeStop is called after the callback to console causing your dudes to occasionally stand there ignoring your onMoveStuck() function. The fix is posted below.

Also a side note: the book "Multiplayer Gaming and Engine Coding for the Torque Game Engine" says this function is "onStuck" not "onMoveStuck" If I didn't look at the C++ code I never would have known... might be worth changing it back or writing a new book...

Here is what I did to fix it. (I think there is a better structure for the if statment but I'm a script kiddy and will have to research that).

Replace the code from the line "// We should check to see if we are stuck..."
Down to the line "// Test for target location in sight if it's an object. The LOS is"

// We should check to see if we are stuck...
		 //gmod improved unstick
		 if( mDamageState != Disabled )
		 {
			 mLocationDiff.x = location.x - mLastLocation.x;
			 mLocationDiff.y = location.y - mLastLocation.y;
			 //if (location == mLastLocation) {
			 if( mLocationDiff.x < 0.01 && mLocationDiff.x > -0.01 &&
				 mLocationDiff.y < 0.01 && mLocationDiff.y > -0.01){
					 //mMoveState = ModeStop;
					 throwCallback("onMoveStuck");
	            
			 }else{
				mLastLocation = location;
			 }
		 }
      }
   }

   // Test for target location in sight if it's an object. The LOS is


#1
06/05/2010 (11:08 am)
The issue was logged. TQA-226
#2
06/05/2010 (1:14 pm)
Or this.

// We should check to see if we are stuck...
		 F32 DistanceFromLastMovement = (location - mLastLocation).len();
         if (DistanceFromLastMovement < 0.01f) {
            throwCallback("onMoveStuck");
#3
06/12/2010 (11:05 am)
Thanks Chris That looks alot better.
#4
04/24/2011 (6:49 pm)
Fixed in 1.1 Final and Preview.