Apex Boids: Emergent Behavior Sandbox
This interactive sandbox was developed following a Master's degree lecture on emergent behaviors. The project explores the transition from theoretical Boids rules to a functional, optimized simulation using Godot 4.5.1.
The Simulation
The simulation features a flock of autonomous agents following the three classic steering rules: Separation, Alignment, and Cohesion. To create a dynamic environment, I introduced an apex predator (the Shark) that hunts the flock.
The real-time interface allows you to manipulate the system's variables:
- Flocking Dynamics: Shift the group from perfect synchrony to total chaos.
- Predation Pressure: Boost the shark's speed to observe panic responses.
- Perception: Change how far each fish "sees" to dictate global group topology.
Technical Implementation
The architecture of this sandbox focuses on balancing algorithmic complexity with stability and high frame rates:
- Spatial Partitioning: To mitigate the O(n2) bottleneck, the simulation uses a grid-based hashing system. Agents only calculate interactions with neighbors in adjacent cells, which is crucial for maintaining stability in a web environment.
- Update Staggering: Agent updates are distributed across frames (time-slicing). This ensures the most fluid experience possible despite the CPU limitations of browser-based execution.
- Object Pooling: The system utilizes a pre-instantiated pool of 200 fish. Nodes are recycled instantly, ensuring zero memory fragmentation and preventing "stuttering" during gameplay.
- Toroidal Seamlessness: The world is mathematically infinite. Agents perceive and move across screen edges flawlessly thanks to a custom wrapped-vector logic.
Tech Stack
- Engine: Godot 4.5.1 (Compatibility mode for Web)
- Language: GDScript 2.0 (Fully typed for performance)
- Optimization: Object Pooling, Spatial Hashing & Frame Staggering..
- Visuals: Custom Line2D trails.
- Version Control: Git (Boids-Behavior-Sandbox)


Comments
Log in with itch.io to leave a comment.
Incroyable, je laisse un like