Flock simulation Unity

Flock simulation
This week we tried to use Unity for something different – a little flock simulation.

We implemented simple BOID algorithm to simulate behavior of Animals flocking.
BOID algorithm consists of three simple steering behaviors:

SEPARATION – steer to avoid crowding local flock-mates
ALIGNMENT – steer towards the average heading of local flock-mates
COHESION – steer to move toward the average position of local flock-mates


Image source: http://www.red3d.com/cwr/boids/

Each agent in simulation is GameObject with BoidAgent scripts attached to it. Script has some public parameters for tweaking and testing different parameters.

You can download our implementation with demo scene here.

Hope this helps somehow! 🙂 If you have any questions don’t hesitate to ask in comments!

  • Avalon

    They seem to be moving around using random goalPosition ? How about if you wanted to flock together and move to a particular goalPosition, for example wherever you click the mouse.