Joseph Carothers
← All projects

Project · Unity

Unity Boid Simulation

I used Unity to see how a flock moves when each bird follows three simple rules.

GitHub ↗November 2021 · 1 min read
Stack
UnityC#
Unity Boid Simulation cover

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

  1. Separation
    Each boid steers away from nearby flockmates to avoid crowding.

  2. Alignment
    Each boid steers toward the average heading of nearby flockmates.

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

Boid Sim

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.