Hey guys
I'm trying to work on getting the collision avoidance working in my Crowd Simulation.
Currently it works to the point where one will stop for the other let it pass then carry on when a certain distance parameter is met. However I want it to work so that the agent will move out the way so to speak so move around a sort of "repel sphere" to keep the distance.
I dont really know how I'd go about this though
//================================================
void agent::avoidOtherAgents()
{
if(this->collisionAgent)
{
return;
}
for(int i = 0; i < NUM_AGENTS; i++)
{
if(this != glWindow->pAgent)
{
float distanceCheck = cVector.getDistance(glWindow->pAgent->getPos(), this->getPos());
if(distanceCheck < 5.0f)
{
glWindow->pAgent->collisionAgent = TRUE;
break;
}
else
{
glWindow->pAgent->collisionAgent = FALSE;
}
}
}
}
//================================================
I made my own vector math library from pretty much the standard vector functions, add/subtract multiply/scalar multiply/divide and so on. But I dont know what I'd need to do to try and get my problem working
Oh thought I'd add this, this is how the agents get their velocity, which I'm guessing is going to need to be changed to
//Subtract the currentPos from the targetPos
svect3 temp;
temp = cVector.vector_SUB(&targetList[index], &pos);
// Normalise the vector for use with the setVel
cVector.Normalise(&temp);
if(collisionAgent == FALSE)
setVel(temp.x / 2, temp.y / 2, temp.z);
else if(collisionAgent == TRUE)
setVel(0.0f, 0.0f, 0.0f);
Even if my code doesnt really help, does anyone know the rough idea of how to do it, or any tutorials/lessons on it?
Many thanks