In the early summer evenings, you have probably seen flocks of birds flying in the sky. You have probably noted how they seem to move as a single living object: they all move in a particular direction, turn around, and grow and shrink. In games, a flocking system aims to replicate this behavior: we want to implement an algorithm to move many objects as an organic group.
In games, we call each element of a flock a boid. To implement a flocking behavior, we do not need to tell each boid what to do; instead, all we need to do is implement a few rules for each boid to follow so that they can flock on their own. In fact, flocking is an excellent example of emergent behavior: each boid reacts exclusively to its neighbor's behaviors; nevertheless, the flock seems to move as if someone were coordinating it.
In this chapter, we will learn what these rules are and how to implement...