A simple 3D Boids simulation in Unity demonstrating flocking behavior.
This project implements a basic Boids algorithm in Unity. Each agent (Boid) follows three main rules:
- Separation: avoid crowding neighbors
- Alignment: align velocity with nearby agents
- Cohesion: move towards the average position of nearby agents
Boids also avoid obstacles within a set radius, and movement is handled with smooth rotation and velocity clamping.
-
Boid Controller (
BoidController.cs)
Controls individual Boid behavior. Applies separation, alignment, cohesion, and obstacle avoidance. Updates position and rotation each frame. -
Camera Controller (
CameraController.cs)
Syncs up the editor camera with the game. -
Physics-Based Vision
Each Boid usesPhysics.OverlapSphereto detect neighbors and obstacles within a vision radius. -
Steering
UsesQuaternion.Slerpto rotate smoothly toward target directions calculated from the flocking rules. -
Velocity and Movement
Forces are applied per frame, then velocity is clamped and drag is applied to smooth movement.
- Flocking behavior with separation, alignment, and cohesion
- Obstacle avoidance
- Adjustable parameters for:
- Speed
- Maximum velocity
- Steering strengths for each rule
- Vision radius