There are three basic rules for flocking behavior.
These rules are applied independently by each boid.
There is no overall, "flock-level" intelligence
guiding them as a group.
Each boid is only aware of the other boids in its immediate vicinity, rather than all boids in the simulated world. The boid applies its rules based on the current positions and velocities of its neighbors.
The rules, in order of precedence, are:
Separation - keep a certain minimum distance from any neighbors, to avoid colliding | |
Alignment - match the direction and speed of neighbors | |
Cohesion - move towards the average position of neighbors |
The Separation and Cohesion rules will work together to bring boids into a group, without them all clumping up into the same spot.
The Alignment rule will cause the boids to move as a group.