A downloadable game for Windows

Boid Sandbox

is my first real exercise in multithreading using Unity's Job System and Burst compilation. But first, it's important to know what boids are exactly.

The wiki page for boids explains it better than I can:    https://en.wikipedia.org/wiki/Boids


Boids are agents modeled after the flocking behaviors of animals like schools of fish or swarms of birds. For more reading on the history of how boids are used practically, there's this great article here: https://beforesandafters.com/2022/04/07/a-history-of-cg-bird-flocking/


For the TLDR, Boids most commonly have 3 forces working simultaneously to drive their behavior:

  1. Cohesion
  2. Alignment
  3. Separation

Cohesion keeps boids sticking together, alignment keeps boids moving in the same direction, and separation keeps boids from bumping into each other.

Grid Optimizations

For this project, I made an additional optimization that's important in this real-time environment. Boids need to know who their neighbors are in order to calculate these driving forces.

So, boids are separated into "grid cells" at the start of every frame, and each boid can find their neighbor in relatively short time by just checking which grid cell they're in and looping over boids in their current and adjacent cells.

These grid cells are invisible and only exist as math, where each boid calculates its cell by taking the floored quotient of its current position and the cell size. The background image of grid lines are just for show.

How Vision Works

When you change the vision radius, you're actually changing how large these grid cells are. If you set the radius to be large, there will be fewer, larger cells, which means each boid will account for more of its neighbors to drive the 3 forces.

However, accounting for more neighbors means there will be an exponentially increasing amount of calculations to  perform, approaching N^2 number of calculations for N boids.

You WILL experience large framerate drops when increasing vision radius with a significant number of boids.

Controls

Use W A S D or middle-click to move the camera, and scroll in and out to zoom.

Music courtesy of:  www.purple-planet.com

Download

Download
BoidSandboxRelease1.zip 49 MB

Install instructions

  1. Download the zip file
  2. Extract the zip file to somewhere on your computer
  3. Double click the .exe to run the game

Leave a comment

Log in with itch.io to leave a comment.