← 🧬 Biology & Life

🐦 Boids

Agents: 300
FPS:

Drag — rotate · Scroll — zoom

🐦 3D Boids — Flocking Agents

Craig Reynolds' Boids algorithm shows how three simple rules — separation, alignment, and cohesion — produce the complex, lifelike flocking behaviour seen in birds, fish, and insects.

🔬 What It Demonstrates

Three rules govern each agent: avoid neighbours (separation), steer toward the group's average direction (alignment), and move toward the group's centre (cohesion). From these local interactions, complex flocking patterns emerge globally.

🎮 How to Use

Drag the sliders to adjust each rule's weight. Increase cohesion for tight flocks, separation for spread-out swarms. Change speed or add wind to see how the flock responds.

💡 Did You Know?

The Boids algorithm was published by Craig Reynolds in 1987 and was used in the film Batman Returns (1992) to simulate bat swarms — one of the first uses of AI-driven extras in cinema.

About this simulation

This simulation runs Craig Reynolds' Boids model on up to 600 autonomous agents in genuine 3D space, rendered with WebGL. Each cone-shaped agent steers using only three local rules — separation, alignment and cohesion — applied to neighbours found within a perception radius. No global choreography exists; the flock's coordinated motion is purely emergent. A spatial hash grid keeps neighbour searches efficient, so hundreds of boids update smoothly each frame inside a soft-walled bounding box.

🔬 What it shows

Reynolds' 1987 flocking algorithm. Every frame, each boid sums three weighted steering forces — separation (push from very close neighbours), alignment (match neighbours' average heading) and cohesion (drift toward neighbours' average position) — then its velocity becomes v' = v + w_s·S + w_a·A + w_c·C, with each force clamped so motion stays smooth.

🎮 How to use

Sliders set Count (50–600 boids), Speed, the Separation, Alignment and Cohesion weights (0–3 each), and Perception radius (1–12). Tick Predator to release a red hunter the flock flees, with its own Pred. speed slider. Press Rebuild to reset, drag to rotate the camera and scroll to zoom.

💡 Did you know?

Reynolds' Boids debuted in cinema in Batman Returns (1992), animating swarms of bats and a stampede of penguins — among the earliest uses of autonomous flocking agents on screen.

Frequently asked questions

What is the Boids model?

Boids is an artificial-life algorithm published by Craig Reynolds in 1987 to recreate the flocking of birds, schooling of fish and swarming of insects. Each agent (a bird-oid object, or boid) follows three local steering rules with no leader and no central plan, yet coordinated group motion emerges. It is a classic demonstration of how simple local interactions can generate complex global behaviour.

How do the three rules actually work?

For each boid the simulation scans nearby agents within the perception radius and computes three steering vectors: separation pushes away from neighbours that are too close, alignment nudges its heading toward the average velocity of nearby boids, and cohesion pulls it toward their average position. These are weighted by the sliders, clamped to a maximum force, and added to the current velocity each frame.

What do the Separation, Alignment and Cohesion sliders change?

Each slider sets the weight (0 to 3) of one steering rule. Raising Cohesion produces tighter, denser flocks; raising Separation spreads agents out and prevents crowding; raising Alignment makes the group move in a more unified direction. Balancing the three is what yields the natural, swirling flock motion, and extreme settings can break the flock apart or collapse it.

What does the Perception radius do?

The perception radius (1 to 12 units) sets how far each boid can sense other agents. A small radius means boids react only to immediate neighbours, giving looser, more fragmented groups; a large radius lets each boid respond to many others, producing larger, more synchronised flocks. The simulation also uses this radius as the cell size of its spatial hash grid for fast neighbour lookups.

Is this an accurate model of real animal flocking?

It captures the essential principle confirmed by biologists — that flocking arises from local rules rather than central control — and remains the standard teaching model. Real starlings, however, track a roughly fixed number of nearest neighbours (about seven) rather than everything inside a fixed radius, and real animals add factors such as vision limits and predator response. This version is a faithful, illustrative approximation, not a precise biological reconstruction.

About 3D Boids — Flocking Agents

The Boids simulation models the flocking behaviour of birds, the schooling of fish, and the swarming of insects using three simple local steering rules invented by Craig Reynolds in 1987. Each agent — called a boid, short for bird-oid object — independently applies separation (avoid crowding), alignment (match neighbours' heading), and cohesion (move toward neighbours' centre) every frame, with no central controller. The result is strikingly lifelike coordinated motion that emerges entirely from local interactions, making Boids a textbook example of emergent complexity in artificial life.

Reynolds first published the algorithm at SIGGRAPH 1987, and it was deployed in cinema the same decade: Tim Burton's Batman Returns (1992) used Boids to procedurally animate swarms of bats and a stampede of penguins. Today the model underpins crowd simulation in games, autonomous drone-swarm coordination, and biological studies of collective animal behaviour.

Frequently Asked Questions

What are boids and what do they simulate?

A boid (bird-oid object) is a simulated autonomous agent that follows three local steering rules: separation, alignment, and cohesion. The model was created by Craig Reynolds in 1987 to reproduce the emergent flocking of birds, schooling of fish, and swarming of insects without any central choreography. Watching a few hundred boids produces the same swirling, cohesive group motion observed in real animal aggregations.

How do the simulation controls work?

The Count slider sets the number of agents (50 to 600); Speed sets their base movement rate. Separation, Alignment, and Cohesion sliders each weight one steering rule from 0 to 3 — raise Cohesion for tighter flocks, raise Separation to spread agents out, raise Alignment for more synchronised headings. The Perception radius slider (1 to 12 units) controls how far each boid senses its neighbours. Enable the Predator checkbox to release a red hunter the flock flees, and press Rebuild to reset positions. Drag to rotate the camera; scroll to zoom.

What is emergent behaviour and why do boids demonstrate it?

Emergent behaviour arises when a system's global patterns cannot be predicted from its individual parts in isolation. In Boids, each agent follows only three rules involving its immediate neighbours, yet the group as a whole produces coherent, bird-like flocks that split around obstacles, reform after disturbances, and rotate together. No rule says "form a flock" — the flock is an emergent property of the local interactions, which is why Boids remains one of the most cited examples in complexity science and artificial life.

What is the mathematics behind the three steering rules?

Each frame, for boid i with velocity v and position p, the simulation computes three steering vectors within the perception radius r: Separation S = sum of (p_i - p_j) / |p_i - p_j|^2 for close neighbours j; Alignment A = average velocity of neighbours normalised to the target speed; Cohesion C = (average position of neighbours - p_i) normalised and scaled to target speed. The new velocity is v' = v + w_s * S + w_a * A + w_c * C, where w_s, w_a, w_c are the slider weights. Each force vector is clamped to a maximum magnitude (MAX_FORCE) to keep motion smooth, and the final speed is clamped to 1.4 times the base speed.

How is the simulation fast enough to handle hundreds of agents in real time?

A naive implementation checks every pair of boids for proximity, costing O(N^2) operations per frame — too slow for 600 agents at 60 fps. This simulation uses a spatial hash grid: each frame, all boids are bucketed into grid cells of size equal to the perception radius. To find neighbours, a boid only checks the 3x3x3 = 27 surrounding cells instead of the full list, reducing the average cost to O(N * k) where k is the number of boids per local cell. The WebGL InstancedMesh renderer then draws all cones in a single draw call, keeping GPU overhead minimal.

Do real birds and fish actually follow these three rules?

Empirical research confirms that real flocking is local and decentralised, consistent with the Boids principle. However, studies of starling murmurations (notably by Ballerini et al., 2008) show that real starlings interact with a roughly fixed number of nearest neighbours — about six or seven — regardless of density, rather than with every agent within a fixed radius. Real animals also incorporate vision-angle limits, noise tolerance, and predator-specific escape manoeuvres. Boids is an accurate qualitative model of the emergent mechanism but is not a quantitatively precise biological reconstruction.

Who invented the Boids algorithm and when?

Craig W. Reynolds, then at Symbolics, presented the Boids algorithm in the paper "Flocks, Herds, and Schools: A Distributed Behavioral Model" at SIGGRAPH 1987. Reynolds coined the word "boid" as a contraction of "bird-oid object." The paper was revolutionary because it showed that convincing collective animal motion could arise from a handful of simple local rules rather than scripted paths, and it effectively launched the field of autonomous agent simulation in computer graphics.

What other phenomena are related to Boids-style modelling?

Boids belongs to a broader family of agent-based and swarm models. Closely related are ant colony optimisation (ACO), where virtual ants deposit pheromone trails that guide the colony toward food; particle swarm optimisation (PSO), which uses Boids-like velocity updates to search for optimal solutions; Reynolds' later steering behaviours (seek, flee, pursue, evade, wander); and cellular automata such as Conway's Game of Life. In biology, the same framework is used to model swarming locusts, schooling sardines, and even the collective motion of bacteria and human pedestrians.

How is Boids used in engineering and technology today?

Reynolds' algorithm, or derivatives of it, is used in video-game crowd and traffic AI (the Half-Life series, Unreal Engine's AI systems), film VFX for large creature crowds (The Lord of the Rings, World War Z), and architectural pedestrian-flow simulations for stadium and transit-hub safety. In robotics and aerospace, multi-UAV swarm coordination adopts the same separation-alignment-cohesion structure to keep drone formations collision-free while pursuing a collective goal. Boids also appears in network routing research, where packets are treated as agents navigating congestion.

What are current research frontiers in flocking and swarm intelligence?

Active research areas include topological interaction rules (neighbours defined by rank rather than distance), noise-robust flocking near the order-disorder transition (a connection to statistical physics and active matter), data-driven boids calibrated from GPS-tracked animal trajectories, and heterogeneous swarms where agents have different roles or capabilities. On the engineering side, real-time decentralised control of hundreds of physical drones — using only local wireless communication and onboard sensing — is an open problem that draws heavily on Boids theory, as does the design of resilient swarms that maintain cohesion when some agents fail.