So I am using Boids to create flocking behavior for large amount of zombies.The problem I have is in my Separation pass I check the distance of each zombie compared to each zombie. I think this is wrong.
void Seperation (float MaxDistance){
int TempInt = 0;
int SubCount = 0;
//HiveMind is the parent of all the zombies
while (TempInt < HiveMind.transform.childCount) {//So this will run once each child
while (TempInt < HiveMind.transform.childCount){//The problem is now I need to run every zombie again to check there distance
float Distance = GetDistanceOf(HiveMind.transform.getChild(TempInt),HiveMind.transform.getChild(SubCount));
if (Distance < MaxDistance){
AvoidFlockMember(HiveMind.transform.getChild(SubCount));//This moves away from the flock member.
}
SubCount +=1;
}
TempInt +=1;
}
}
This isn't exact but should give an idea.
This causes a exponential cost. 10 Zombies need to check all of the zombies 10*10 = 100 loops. Not bad but 1 000 *1 000 = 1 000 000 loops. So I am getting a power of two amount of loops.
I feel that there is some thing simple I am missing?