# Stationary Flock Logic

I'm trying to simulate a tabletop skirmish game and thus creating units that "stick together" meaning they move like a swarm and occupy the smallest space possible when idle (they have base 1" spacing between them and I can increase the spacing to "spread" the unit).

Fallowing the concept of Boids and drawing inspiration from this paper, I managed to come up with the fallowing steps:

1. identify the center of mass of the unit
2. sort the models in the unit from the closest to the furthest to the center
3. fallowing this order, move each model as closer to the center as it can without getting too close to other models

In my idea this was the simplest viable solution and it had the advantage to "stabilise" the unit, meaning that at one point all the models would reach a condition where no further movement would be possible and they'd settle there.

Or would they?

What I didn't consider is that of course moving them models would also change the center of mass of the unit, so I found my unit roaming around the battlefield on its own. Of course I understand that flock logic is intended for moving formations so it's not really fitting my goal.

At the moment I managed to solve the issue like this:

1. calculate the center of mass
2. move all the models based on the center of mass from step 1
3. calculate the new center of mass
4. translate the whole unit so that the new center of mass is moved to the old one

This works but feels kinda off.

How could I update my algorithm to preserve the center of mass without that ugly "mass translation"?