Skip to content
CoreSource checked

Boids Flocking

Simulates flocking from local separation, alignment, and cohesion rules.

Quick Facts

Compact metadata for implementation and discovery.

Category
Simulation
Difficulty
Beginner
Family
Agent-Based Simulation
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
2
Code example
Ready
Visualization
Ready

Overview

Boids update each agent from nearby neighbors: separation avoids crowding, alignment matches heading, and cohesion steers toward the local group.

Core Concepts

local neighborhoodseparationalignmentcohesion

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n^2)

Worst

O(n^2)

Space

O(n)

When to Use

  • Use when plausible group motion is more important than physical accuracy.
  • Use when local-neighborhood rules can produce the desired behavior.

When Not to Use

  • Avoid when exact physical simulation or strategic planning is required.
  • Avoid when neighbor search cost is too high without spatial acceleration.

What It Does

  • Finds nearby agents
  • Computes separation, alignment, and cohesion steering
  • Updates velocity and position for each agent

Use Cases

  • Flocking animation
  • Crowd-like procedural motion
  • Agent-based behavior demonstrations

Inputs

  • Current state
  • Forces or constraints
  • Time step

Outputs

  • Updated state
  • Constraint corrections
  • Collision results

Key Formulas (1)

Boid velocity

vnext = v + wsep·sep + walign·align + wcoh·coh
v_next = v + w_sep*sep + w_align*align + w_coh*coh

Combines local steering rules into the next velocity.

Pseudocode

  1. 1.For each agent, find neighbors within the perception radius
  2. 2.Compute separation from very close neighbors
  3. 3.Compute alignment from average neighbor velocity
  4. 4.Compute cohesion toward average neighbor position
  5. 5.Clamp steering and update velocity and position

Canonical Example

Input
three agents, with one too close and two moving right
Output
the crowded agent steers away while still partly aligning right
Explanation
The final steering vector combines separation, alignment, and cohesion weights.

Implementation Notes

  • Compute all steering forces from the previous frame before applying updates.
  • Clamp velocity and steering magnitudes.
  • Use a grid, quadtree, or spatial hash for larger flocks.

Common Pitfalls

  • Large timesteps or steering weights can cause jitter or explosions.
  • Naive all-pairs neighbor checks do not scale well.
  • Updating agents in-place can make behavior depend on iteration order.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show state updates, constraints, and error correction over simulation steps.

Boids Flocking mechanism walkthrough step 1 of 5x₀x₁x₂x*
Step 1 of 5: For each agent, find neighbors within the perception radius
simulation-mechanism

Notes

Boids are behavioral rules, so parameter tuning and deterministic update order matter more than physical correctness.

Sources (1)

What each reference supports for this entry.

Reynolds Boids

Paper

Original flocking model reference supporting Boids Flocking.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborN-Body Simulation

Both update many interacting agents or particles.

Conceptual neighborParticle Swarm Optimization

Both use local agent interactions to produce collective behavior.

Tags

SimulationFlockingAgent BasedParticles