In this chapter, we learned how to implement a flocking behavior system. We implemented it using custom direction vectors to control the boids' movement that we calculated by applying Craig Reynolds' three main flocking concepts—alignment, coherence, and separation. We then applied our flocking behavior to the flying objects, but you can apply the techniques in these examples to implement other character behaviors, such as fish shoaling, insects swarming, or land animals herding. You'll only have to implement different leader movement behaviors, such as limiting movement along the y axis for characters that can't move up and down. For a 2D game, we would just freeze the y position. For 2D movement along uneven terrain, we would have to modify our script to not put any forces in the y direction.
We also took a look at crowd simulation and even...