Three rules, no leader
Nobody leads the flock and no bird knows its shape. Each bird looks only at the few birds near it
and follows three simple rules. The flock comes out of that.
Craig Reynolds called these simulated birds “boids” in 1987. Films and games still use his rules for flocks, herds and crowds.
1. Each bird sees only its neighbours
The highlighted bird sees the birds inside its shaded area: a short distance, and not straight behind it.
Those are its neighbours. It reacts to them and ignores everyone else.
Change View distance and View angle below to change what it sees.
2. Separation: don't crowd
Only separation is on. Each bird steers away from neighbours that are too close (inside the dashed circle).
The red arrow is that push. Birds spread out evenly, but each keeps its own heading.
3. Alignment: go the same way
Only alignment is on. Each bird turns toward the average heading of its neighbours
(blue arrow). Soon whole groups fly in step, but nothing keeps them together or apart.
4. Cohesion: stay with the group
Only cohesion is on. Each bird steers toward the middle of its neighbours (green arrow).
Birds pull together into small knots that tumble about: no shared direction, and nothing stops them piling on top of each other.
5. All three together
Separation keeps space, alignment lines them up, cohesion holds them together. With all three, you get
a flock: groups that split around a rock, join up again and turn as one.
The arrows are added up, and the bird turns a little toward the total each step. It can only turn so fast and keeps flying.
Now play
Try the presets, change the strengths, tap to scatter the birds like a hawk would, or add rocks and switch to walls.
Small changes to the rules give very different crowds.