Three local rules, no central controller
Every drone in this swarm decides its own next move using only what it can see of its immediate neighbours — there is no leader broadcasting positions and no central planner computing a global path. This is Craig Reynolds' 1987 boids model, three simple steering rules blended together, and it is the same algorithm that produces convincing flocks of birds and schools of fish on screen. The coherent, coordinated-looking Flock formation you see in this simulation emerges entirely from local interactions.
Separation, alignment, cohesion
separation = Σ (pos_self − pos_j) / dist(j)² for each neighbour j within a short radius alignment = average(vel_j) − vel_self for each neighbour j within the flock radius cohesion = average(pos_j) − pos_self for each neighbour j within the flock radius steer = w1·separation + w2·alignment + w3·cohesion (clamped to max steering force)
Separation pushes a drone away from neighbours that get too close, weighted more strongly the closer they are, which is what prevents mid-air collisions in a dense swarm. Alignment steers a drone to match the average heading of nearby drones, which is what makes the whole group turn together rather than tangle. Cohesion pulls a drone gently toward the average position of its neighbours, which is what keeps the swarm from dispersing. None of the three rules references any drone outside a short local radius, and none of them references a fixed destination — the flocking behaviour is a pure side effect of every drone reacting only to who is nearby.
Turning a flock into a formation
Free flocking is only one of the four modes here. Circle, Grid and V-Shape add a fourth term: a mild attraction toward each drone's assigned slot on a target shape, computed once from the formation centre. Crucially this is added on top of the boids forces, not instead of them — separation still prevents collisions inside the formation, and the result is a swarm that self-assembles into the target pattern while still avoiding internal collisions and reacting smoothly if a drone is knocked off station. Click anywhere on the canvas and the formation centre relocates there, and every drone's target slot updates, producing a fluid migration rather than a teleport.
Why real swarms use exactly this kind of local rule
A central controller that tracks every drone's state and computes a global optimal trajectory does not scale: communication bandwidth, computation and the failure of a single point all get worse as the swarm grows, and the whole system halts if the coordinator drone goes down. Local rules scale to arbitrarily large swarms with roughly constant per-drone computation (bounded by the number of drones within the interaction radius, not the total swarm size), degrade gracefully when individual drones fail or drop out of communication, and require no single point of failure — properties that make boids-style control the practical starting point for real multi-drone systems in warehouse logistics, light shows, and search-and-rescue coverage, on top of which engineers add collision-avoidance guarantees and formation-specific potential fields.
Tuning the three weights
The character of the swarm is set almost entirely by the relative weights on the three forces. Heavy separation and light cohesion produces a loose, spread-out swarm that avoids clumping; heavy cohesion and light separation produces a tight cluster that risks near-collisions; heavy alignment produces a swarm that turns as one smooth wave rather than churning internally. Real flight controllers additionally cap acceleration and turn rate to match a drone's actual physical limits, which is why the steering force in the formula above is clamped — without a limit, a sudden burst of nearby neighbours can otherwise demand an instantaneous velocity change no real rotor can deliver.
Frequently asked questions
Does any single drone in the swarm know the shape of the whole formation?
No. Each drone only needs its own assigned target slot (in formation modes) and the positions and velocities of nearby drones within a short interaction radius. The overall formation shape emerges from every drone independently following the same local rules, not from any drone holding a global map.
Why doesn't the swarm collide with itself when it's tightly packed?
The separation force grows sharply as neighbours get closer, actively pushing drones apart before they get too close together. It operates continuously alongside cohesion and alignment, so drones are pulled together at long range but pushed apart at short range, settling into a stable spacing.
What happens if you increase the cohesion weight relative to separation?
The swarm packs more tightly, since each drone is pulled more strongly toward its neighbours' average position and pushed back less strongly when they get close. Pushed too far, this raises the risk of near-collisions, which is exactly the trade-off real flight controllers tune carefully against.
Try it live
Everything above runs in your browser — open Drone Swarm and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Drone Swarm simulation