Basic flocking behavior
As we said in the introduction to this chapter, we can describe a flocking behavior by using just three intuitive properties:
- Separation: This property, also called short-range repulsion, represents the minimum distance between neighboring boids to avoid collisions. You can imagine this rule as a force that pushes a boid away from the others.
- Alignment: This property represents the likelihood for each boid to move in the same direction as the flock (we measure this as the average direction of all the individual boids).
- Cohesion: This property, also called long-range attraction, represents the likelihood for each boid to move toward the center of mass of the flock (we measure this by averaging the position of each boid in the flock). Thus, you can imagine this rule as a force that pushes a boid toward the center of the flock.
In this demo, we will create a scene with flocks of objects and implement the flocking behavior in C#. For this...