boids

Flocking Behaviour

Emergent behaviour from a simple set of rules.

Simulating lifelike behaviour in game entities always struck me as something that would always be incredibly complicated. However sometimes even with just a few rules complex emergent behaviour can be created. Such in the case with Boids. Boids are a flocking creature designing originally by Craig Reynolds and at their core there are just three logic rules:

  • Separation - Boids don't want to be flying too close to another Boid
  • Alignment - Boids want to be flying in the same direction as nearby Boids
  • Cohesion - Boids want to be in the centre of nearby Boids

In my Javascript implementation I also added a varied speed property to each individual, this prevents the flocking from continuously travelling in the same direction. As the faster flock mates push through to the front of the group it moves the centre of mass of the flock, causing the whole flock to change direction.

The controls below show the radius of the effect of the various rules. Changing the values will result in different flocking behaviour, for example shrinking the separation constraint will result in the Boids flying closer together.