cohesion static method
Vector3
cohesion(})
Computes a cohesion force steering towards the center of mass of neighborPositions.
Implementation
static vm.Vector3 cohesion(
vm.Vector3 currentPos,
vm.Vector3 currentVel,
List<vm.Vector3> neighborPositions, {
double maxSpeed = 5.0,
double maxForce = 10.0,
}) {
if (neighborPositions.isEmpty) return vm.Vector3.zero();
var center = vm.Vector3.zero();
for (final p in neighborPositions) {
center += p;
}
center /= neighborPositions.length.toDouble();
return seek(
currentPos,
currentVel,
center,
maxSpeed: maxSpeed,
maxForce: maxForce,
);
}