Jump to content

small problem in setPathDestination


deathbravo

Recommended Posts

i tried to spawn 150 bots to fight. and the bots using setPathDestination to follow a path while performing patrol.

I found they will stuck after killing the player and go back to a path node in a crowd.

I read the aiplayer.cpp and found there is a OnStuck function has the ability to repath the bot.

but the function plan path only considering static items in the map, if another bot blocked the way, the repath can't detour with bots.


then I tried to add some code to see if our bot is stuck by other bot or player, then try to detour.

the code is a modified version of the findcover.


i am not sure if there is any cooked function to solve it and i missed it. if there is, i want to use the stock feature.


struct BlockerSearch

{

Player *blocker;

U32 count;

BlockerSearch()

{

count = 0;

}

};


static void isBlockerAICallback(SceneObject *obj, void *key)

{

Player *p = dynamic_cast(obj);


BlockerSearch *s = static_cast(key);


s->count++;


s->blocker = p;


}


bool AIPlayer::isBlockerAI(){


F32 width = mScaledBox.len_y();

Point3F forwardOffset;

forwardOffset[0] = width/2.f;

forwardOffset[1] = width/2.f;

forwardOffset[2] = width/2.f;


// Create a search state.

BlockerSearch s;


Box3F box(width /2.0f);//* 2.0f);

Point3F center = getPosition();

const MatrixF& transform = getTransform();

Point3F forwardVector = transform.getForwardVector();

center = center + forwardVector + forwardOffset;


box.setCenter(center);


U32 mask = PlayerObjectType;// | AIObjectType;


getContainer()->findObjects(box, mask, isBlockerAICallback, &s);

//Con::errorf("searching found: (%u)",s.count );


if(s.blocker)

{

return true;

}

return false;

}


void AIPlayer::detorAI(){

F32 width = mScaledBox.len_y();

Point3F backOffset;

backOffset[0] = width;

backOffset[1] = width;

backOffset[2] = width;


Point3F center = getPosition();

const MatrixF& transform = getTransform();

Point3F forwardVector = transform.getForwardVector();

center = center - forwardVector - backOffset;

setMoveDestination(center,false);

}



///////change the onStuck like this , it could back one step to make room for each other

void AIPlayer::onStuck()

{

#ifdef TORQUE_NAVIGATION_ENABLED

if(!mPathData.path.isNull()){

if( isBlockerAI()){

detorAI();

}else{

repath();

}

}else

#endif

throwCallback("onMoveStuck");

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...