Unity Boid Simulation
I wanted to see how much flocking behavior I could get out of a few rules. I built this in Unity and C#.
I used Craig Reynolds' Boids algorithm. Each boid adjusts its movement using the three rules below.
Flocking Behaviors
-
Separation
Each boid steers away from nearby flockmates to avoid crowding. -
Alignment
Each boid steers toward the average heading of nearby flockmates. -
Cohesion
Each boid steers toward the average position of its neighbors.
The weights for these rules are adjustable, changing how the flock moves.
Predator Simulation
I added a basic predator that the boids avoid while continuing to flock.
Visual Representation
To provide a visual example of the flocking behaviors in action, here’s a preview of the simulation:

The animation shows the boids avoiding obstacles and reacting to the predator.
What I Learned
I spent time tuning the weights of those rules to get the flock to move naturally.
Project Links
- Source Code: GitHub Repository
