small problem in setPathDestination

There are no stupid questions, just stupid answers.
3 posts Page 1 of 1
deathbravo
Posts: 50
Joined: Mon Feb 01, 2016 7:06 am
by deathbravo » Sun Feb 28, 2016 5:12 am
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<Player*>(obj);

BlockerSearch *s = static_cast<BlockerSearch*>(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");
}
Azaezel
Posts: 488
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Mon Feb 29, 2016 6:32 am
For bots pathing around one another, Try a scheduled NavmeshUpdateAll(%this,true);

Do ensure though you've got https://github.com/GarageGames/Torque3D/pull/1475/files rolled on in though unless you want your memory eaten alive.
deathbravo
Posts: 50
Joined: Mon Feb 01, 2016 7:06 am
by deathbravo » Mon Feb 29, 2016 9:55 am
thanks Azaezel

it seems I did 1 more stupid thing.
3 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests