The Three Rules: How Local Behavior Produces Global Motion

The Rules Defined Precisely

Craig Reynolds’ 1987 SIGGRAPH paper defined three steering behaviors, each computed as a vector from the positions and velocities of neighbors within a perception radius. The rules operate simultaneously, and their outputs are combined as a weighted sum to produce a single velocity update per time step.

Separation computes a repulsive steering vector. For each neighbor within a short-range avoidance radius r_s, the boid calculates the displacement vector pointing away from that neighbor, scaled inversely by distance — closer neighbors exert stronger repulsion. The separation vector is the sum (or average) of these displacement vectors. Mathematically: v_sep = sum over neighbors j of (position_i - position_j) / |position_i - position_j|^2. The effect is a force that increases sharply as neighbors approach, preventing collision and collapse. Without this rule, agents converge to a single point.

Alignment computes a heading-matching vector. The boid calculates the average velocity vector of all neighbors within the perception radius r and steers toward that average. The alignment vector is the difference between the average neighbor heading and the boid’s current heading: v_align = (average_velocity_neighbors - velocity_i). This is the rule responsible for coordinated motion. When a majority of neighbors head in one direction, the boid adjusts to match. Information about direction propagates through the flock because overlapping neighborhoods carry the signal from one boid’s adjustment to the next.

Cohesion computes an attractive steering vector. The boid calculates the centroid (average position) of all neighbors within the perception radius and steers toward it: v_coh = (centroid_neighbors - position_i). This keeps the flock together. Without cohesion, aligned agents would drift apart indefinitely — matching headings but occupying an ever-expanding volume.

The final velocity update combines all three: v_new = w_s * v_sep + w_a * v_align + w_c * v_coh, where the weights w_s, w_a, w_c control the relative influence of each behavior. The resulting vector is clamped to a maximum speed and minimum speed. Reynolds’ original implementation also included a maximum steering force — the rate at which an agent can change direction per time step — which prevents the instantaneous 180-degree turns that no physical bird or robot can execute.

The weights are the primary tuning mechanism. High separation weight produces a sparse, jittery flock. High alignment weight produces tight directional agreement but can cause the flock to be slow to change course. High cohesion weight produces a dense cluster that may oscillate as agents overshoot the centroid. The balance that produces naturalistic flocking is a matter of empirical adjustment — Reynolds tuned it by visual inspection for his 1987 demonstration.

The Perception Radius and Why It Matters

The perception radius r defines which other agents count as neighbors. Only agents within this radius contribute to the three steering calculations. Agents outside it are invisible — they have no effect on behavior whatsoever. This constraint is what makes the model a model of local rules rather than global coordination.

If the perception radius is set to infinity — every agent sees every other agent — then each boid computes its alignment vector from the entire population’s average heading. The flock converges to a uniform heading almost immediately, and the spatial structure of the flock becomes irrelevant. This is global averaging, not local interaction, and it produces unrealistic behavior: instantaneous consensus, no traveling waves of turning, no spatial variation in density or heading.

If the perception radius is too small — smaller than the typical inter-agent spacing — most boids have no neighbors and behave independently. The flock fragments into isolated individuals or tiny clusters that cannot coordinate.

The interesting regime is intermediate: each agent sees a moderate number of neighbors (typically 5 to 15 in Reynolds’ original demonstrations), and the neighborhoods of adjacent agents overlap. It is this overlap that creates the network through which information propagates. When boid A adjusts its heading because of neighbor B, and boid C shares some neighbors with A, C’s next update reflects A’s adjustment. The result is a propagating wave of heading change — the mechanism behind coordinated flock turning.

Biologically, the perception radius corresponds to the sensory range of a real animal: the distance at which a bird can visually track another bird’s position and heading, or the distance at which a fish can detect neighbors via its lateral line or vision. Ballerini et al.’s 2008 finding that starlings use a topological neighborhood (fixed number of nearest neighbors, approximately seven) rather than a metric neighborhood (fixed radius) suggests that real birds solve the density-dependence problem by tracking a constant count of neighbors regardless of spacing. This modification preserves the local-interaction architecture while making flock coherence robust across a wider range of densities.

What Happens If You Remove Each Rule

The three rules are individually necessary and collectively sufficient. Removing any one produces qualitatively different behavior that does not resemble flocking.

Without separation. Agents converge on the centroid of their neighborhood and pile up. The cohesion rule pulls them inward; the alignment rule keeps them heading in the same direction; but nothing prevents them from occupying the same position. The result is a dense, collapsing cluster — not a flock but a point mass. In simulation, agents oscillate around the centroid as cohesion overshoots and then corrects, producing a jittery, contracted clump.

Without alignment. Agents cluster (cohesion pulls them together) and maintain spacing (separation pushes them apart), but they have no directional agreement. The result is a swarm rather than a flock — a cloud of agents maintaining relative position but heading in uncoordinated directions. The group may drift collectively if initial headings happen to be correlated, but it does not exhibit the coordinated turning, the traveling waves, or the obstacle-splitting behavior that define flocking. Alignment is the rule that makes a flock a flock.

Without cohesion. Agents that happen to be near each other align and separate, producing short-lived local coordination. But there is no attractive force to keep the group together. Agents at the periphery, with neighbors only on one side, drift outward. The flock disperses. Given enough time, the population spreads across the entire space, with occasional ephemeral clusters forming and dissolving as agents pass through each other’s neighborhoods by chance.

This ablation analysis shows that flocking requires all three rules in combination. Separation maintains spacing. Alignment creates directional coherence. Cohesion maintains spatial proximity. None is redundant. The emergent behavior — the flock — exists only when all three operate simultaneously.

The Emergent Behaviors That Result from Their Interaction

When the three rules run together with appropriate weights and a moderate perception radius, the system produces behaviors that exist at the flock level and have no counterpart in the rules.

Coordinated turning. A disturbance at one edge of the flock — a simulated predator, a boundary — causes local agents to adjust their heading via separation and alignment. That adjustment propagates through overlapping neighborhoods as a wave of heading change. The wave crosses the flock in a time proportional to the flock’s diameter divided by the neighborhood size, producing the appearance of a collective turn. No agent decides to turn the flock. The turn is the aggregated result of local adjustments.

Splitting around obstacles. When the flock encounters an obstacle, agents near it steer away (separation). The heading change propagates outward (alignment), splitting the flock into two streams that pass around opposite sides. On the far side, as the streams’ neighborhoods begin to overlap again, cohesion pulls agents toward the growing centroid of the reunited group. The flock rejoins. This obstacle-avoidance behavior was not designed and was one of Reynolds’ most striking early demonstrations.

Mill formation. Under certain parameter regimes — particularly high alignment weight with low cohesion — agents form a rotating torus, or mill, where the entire group circles a common center. The mill is a stable attractor: once formed, it persists indefinitely. Mills are observed in real fish schools and have been studied in simulation by Couzin et al. (2002), who showed that the transition between milling and directed motion depends on the ratio of alignment zone to attraction zone in the perception model.

Density waves and band formation. In large flocks, density fluctuations propagate as waves. A region of locally higher density produces stronger alignment and cohesion, which attracts more agents from adjacent regions, which increases density further. The result can be traveling bands of higher density — visible in large-scale simulations and analogous to density waves in real starling murmurations.

These behaviors are emergent in the precise sense: they are properties of the system that do not appear in the specification of any individual agent. The rules mention positions, velocities, and neighbors. The flock-level properties — shape, coherence, turning rate, obstacle response — are consequences of the rules’ interaction, not features of the rules themselves.


Further Reading