Watch a flock of starlings pour across an evening sky — a murmuration — folding, splitting, rejoining, a thousand birds moving as one shimmering sheet with no conductor and no plan. For a long time people assumed such coordination needed a leader, or telepathy, or a global choreography beamed into every bird. In 1987 Craig Reynolds showed it needs none of those. He built simulated birds he called boids (“bird-oid objects”), gave each one just three simple rules about its nearby neighbours, and let them fly. Realistic flocking emerged — lifelike, unrepeatable, and entirely un-scripted.
This is one of the founding demonstrations of emergence: complex, organic group behaviour arising from many agents each following the same tiny local recipe. The same three rules, re-weighted, give you schooling fish, herding sheep, and swarming insects. Boids have flown in films (the bats and penguins of Batman Returns), games, and countless crowd shots since. Here we pin down the three rules precisely, work the vector arithmetic for a single boid, and see why the interaction must stay local.
Each boid is a point with a position
That is the whole engine. There is no leader, no global path, no central plan — every boid runs the identical local computation, and the flock is what all those little decisions add up to. Separation pushes boids apart; cohesion pulls them together; alignment lines them up. Held in tension, they produce a group that is neither a rigid lattice nor a scattering cloud, but a living, breathing flock.
Let a boid have neighbours
Each rule earns a weight —
The weights are the personality dials. Crank cohesion and drop separation and you get a tight, dense school of fish; raise separation and loosen cohesion and you get a diffuse, gassy swarm; push alignment hard and the flock stiffens into a marching formation. Tuning those three numbers is how an animator directs the crowd's character without ever scripting a single trajectory.
In pseudocode the per-boid update is short — a superset of JavaScript, so this reads as untyped TypeScript:
Below is our boid
Notice both neighbours sit inside the circle — only those count. A boid far outside the radius exerts no force at all, which is exactly what makes flocking cheap and realistic: real birds react to the handful of neighbours they can actually see, not to the whole flock.
Put boid
Separation — sum the unit vectors pointing from each neighbour back to
So separation steers
Alignment — average the neighbours' velocities:
The two neighbours head in opposite vertical directions, so their average heading cancels — alignment contributes nothing this frame.
Cohesion — steer toward the neighbours' centre of mass, then subtract our own position:
Cohesion points up-and-right, straight at the neighbours' centre — exactly opposite to separation, as
it should be: one keeps the flock together, the other keeps it from collapsing. Now combine with
example weights
Because we weighted separation a little heavier than cohesion, the net steering is a gentle push
away from the crowd —
This is the heart of emergence — and it genuinely surprised people. No boid stores the
flock's shape, counts the population, or plans where the group is going. Each one only ever answers a
purely local question: “Given the few boids I can see right now, which way should I nudge?”
The graceful global pattern — the murmuration folding and splitting — exists nowhere in any individual;
it lives only in the interaction of many identical local decisions. It is the same idea as an
ant colony finding food or a market finding a price: sophisticated collective behaviour with no central
controller. Reynolds' boids became a textbook example precisely because the code is so short and the
result so lifelike that it makes emergence tangible. Related steering ideas — obstacle
avoidance, goal-seeking (a boid also nudged toward a target), fleeing a predator, path following — bolt
straight on as extra weighted forces, which is the subject of
Two classic ways to wreck a flock. First, unbalanced weights. The three forces only produce lifelike motion when they're held in tension — push any one too hard and the flock degenerates:
Good flocking lives in a narrow band where all three roughly balance. Second, keep it
local. It is tempting to let every boid react to all the others — but that is
both unrealistic (a real bird can't see the whole flock, only its neighbours) and
expensive: all-pairs interaction is