Basic flocking behavior

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 ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.