As we said in the introduction to this chapter, we can describe a flocking behavior by using just three intuitive rules:
- Separation: Also called short-range repulsion, this instructs each boid to maintain a minimum distance with neighboring boids to avoid collisions. You can imagine this rule as a force that pushes the boid away from the others.
- Alignment: According to this rule, each boid tends to move in the same direction as the flock (measured as the average direction of all the individual boids).
- Cohesion: Also called long-range attraction, this instructs each boid to move toward the center of mass of the flock (measured by averaging the position of each boid in the flock). You can imagine this rule as a force that pushes the boid toward the center of the flock.
In this section, we'll create our scene with flocks of objects, and will implement...