Boid

Well-known type of agent-based system that realistically simulates the complex flocking behaviors of birds and fish using simple rules. Each "boid" is an autonomous agent that is only aware of its immediate neighbor boids, all following the same three rules:

  1. Separation (collision avoidance): steer to avoid crowding local flockmates
  2. Alignment (velocity matching): steer towards the average heading of local flockmates
    • Note: remember that a vector is a combination of a speed and a direction (heading)!
  3. Cohesion (flock centering): steer to move towards the average position (center of mass) of local flockmates

And here is what those rules look like when applied to a set of agents (boids):

Separation Alignment Cohesion

Additional rules can be implemented to simulate specific behaviors like obstacle avoidance, predator-prey interactions, bait balls, and more.

Articles:

Code projects:

Videos: