Game Development Community

AIPlayer::getAiMove()

by John Klima · in Torque Game Engine · 06/19/2005 (11:45 am) · 2 replies

Hi all,

i'm playing around with aiPlayer, trying to get a number of bots to move around. first off, was wondering why onMoveStuck was never getting called.

in the code it checks to see if it is stuck
if (location == mLastLocation) { ...

problem is, no where in code is mLastLocation ever being set. why not?

so i changed it to this:

// We should check to see if we are stuck...
 if (location == mLastLocation) {
	throwCallback("onMoveStuck");		
	
                 //not sure what state it should be, but if it's stuck
                //i don't think i want it to be ModeStop, what was here originally.
               //regardless, behavior is unclear
                
             mMoveState = ModeMove;		
	
 } else {
	 mLastLocation = location;
 }

which fires the callback, sometimes. i expected that at any moment from frame to frame a bot is in the same position, the callback should be thrown. but i can look at the bots at runtime, they sit there doing nuthin, but the callback is not thrown. why????

thanks,
j

#1
06/20/2005 (10:56 am)
Is that code sitting inside a mMoveState condition? If it requires "ModeMove" before it'll check it's position and that mode isn't being properly set, you'd never reach your callback.
#2
06/20/2005 (3:34 pm)
I worked it out by juggling things around in the aiMove method, and by doing some diff math rather than simply mLastLocation = location. this way the stuck callback occurs at reasonable frequency.

the initial Q still remains though, why does the virgin AIplayer code come "broken." without the end-user actually setting mLastLocation in the c++ code, you will never get the stuck callback to fire. i pity the torque user who cant modify and re-compile the source.

here's what i got in my AIplayer now:
...
  // Move towards the destination
   if (mMoveState == ModeMove || mMoveState == ModeStuck) {


	F32 xDiffLast = 0;
	F32 yDiffLast = 0;

	//first check if we are still in stuck mode from a previous cycle
	if (mMoveState == ModeStuck){
		xDiffLast = mFabs(mStartAvoidLocation.x - location.x);
		yDiffLast = mFabs(mStartAvoidLocation.y - location.y);
		if (xDiffLast + yDiffLast > mMoveTolerance *10){
                                     //okay, i'm far enuf away from my stuck point to call unstuck
                                     //which will re-try moving towards the original goal point    
		      throwCallback("onMoveUnStuck");
		      mMoveState = ModeMove;
		}

	}

                //now check if we are newly stuck
	xDiffLast = mFabs(mLastLocation.x - location.x);
	yDiffLast = mFabs(mLastLocation.y - location.y);

	 // We should check to see if we are stuck...
                 //fiddle with "20" to adjust sensitivity
	if ((xDiffLast + yDiffLast) *20  < mMoveTolerance ){

		//hold onto my initial stuck location	 
		mStartAvoidLocation = location;

                                //script picks a temporary goal point to avoid
		throwCallback("onMoveStuck");  
		
		mMoveState = ModeStuck;		
			
	 }
     
	  mLastLocation = location;

    }
...