Boids simulation implemented in Java using the LibGDX framework. https://ggrainger.epicpages.dev/libgdx-boids/
  • Java 96.5%
  • HTML 1.8%
  • CSS 1.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
George Grainger c46f7d8c4c
All checks were successful
Publish to git pages / build (push) Successful in 2m25s
Some minor obstacle avoidance improvements
2026-08-02 15:29:28 +01:00
.forgejo
.vscode
core Some minor obstacle avoidance improvements 2026-08-02 15:29:28 +01:00
desktop
gradle/wrapper
html
.gitattributes
.gitignore
build.gradle
gradle.properties
gradlew
gradlew.bat
README.md
settings.gradle

LibGDX-Boids

Build Status

A deployment of this simulation can be viewed here

Simulation in progress

Inspired by a video and similar project by Sebastian Lague.
His video can be found here.

The rules that define boids are given by a report he references, which can be found here.

What is a boid?

Boids are an algorithmic approach to simulation of flocking behaviour such as that found in flocks of birds or schools of fish.

They achieve this by following a series of simple rules which are defined in the report above and are as follows:

  • Collision Avoidance: Avoid collisions with nearby flock mates.
  • Velocity Matching: Attempt to match velocity with nearby flock mates.
  • Flock Centering: Attempt to stay close to nearby flock mates.

These are in order of decreasing presidence, meaning that Collision Avoidance is the most important, and Flock Centering is the least important.

Currently, this implementation handles avoidance of collisions with other objects, this is carried out by performing ray casts at increasing angles until an escape route can be found. The boid then turns towards this escape vector.

Spatial partitioning

In an attempt to improve performance of this boid implementation, we make use of spatial partitioning to prevent us from looping over every other boid for each frame, this implementation uses the underlying Box2D physics engine so that boids can only "perceive" other boids that are within a certain radius of them, this radius is defined in Constants.java.

Customising behaviour

The behaviour of the boids can be controlled by editing the values in Constants.java

The values in Constants.java can be adjusted during runtime using the options menu which can be opened with the buttons in the top left of the screen.
The values are not saved on program exit.