Each boid steers using three local rules combined into one acceleration, based only on nearby neighbours —
no boid has global knowledge, yet ordered flocking emerges.
a = w_sep·Σ(away from close neighbours)
+ w_ali·(avg neighbour velocity − v)
+ w_coh·(avg neighbour position − pos)
polarization = |Σ v_i / N| / avg(|v_i|)
- Separation — steers boids away from immediate neighbours to avoid collisions.
- Alignment — matches velocity direction with nearby flockmates.
- Cohesion — pulls boids toward the local group's average position.
- Flock size — number of active boids simulated simultaneously.
- Predator scatter — introduces a moving predator that boids actively flee, breaking up the flock.
This is the classic Reynolds "boids" model, the same emergent-behavior mechanism behind real bird
flocks, fish schools, and animal herds.