Description
This is my implementation of the Boids flocking algorithm. It is written in Rust, built on the Bevy game engine, and compiled to WASM to run in the browser.
The algorithm consists of just 3 rules:
- Separation - Boids steer apart to avoid colliding.
- Alignment - Boids fly in the same direction as their neighbors.
- Cohesion - Boids clump together so as not to fly off alone.
My version of this program has some extra rules governing speed. In short: things below some threshold are sped
up, and things above are slowed down. This is to keep an appropriate amount of kinetic energy in the system.
Since the boids start in a circle with the same speed, the sum of all velocity vectors is vec2(0, 0).
Technically, floating-point rounding errors would likely mean the system always has some energy, but never
enough for an interesting simulation.