KAgent cohesion
From KokkugiaWiki
arguments:
pop (ArrayList): an arraylist of the population of agents which it will cohere to.
returns:
a vector which is the sum of the cohesion required from the nearest neighbors with an inverse weighting based on distance.
// cohesion
kVec cohesion (ArrayList pop) {
kVec sum = new kVec(0,0,0);
int count = 0;
for (int i = 0 ; i < pop.size(); i++) {
kAgent other = (kAgent) pop.get(i);
float dist = pos.distance(other.pos);
if ((dist > 0) && (dist < rangeOfVision)) {
sum.plus(other.pos);
count++;
}
}
if (count > 0) {
sum.scale(1/(float)count);
return steer(sum, ht);
}
return sum;
}
