Boids Interactive
An interactive version of Craig Reynolds's boids simulation containing 90 agents, with modifications and additions made to the original framework to facilitate the interactive creation of generative art.
Fast Facts
Role: Sole Developer, AI Programming
Timeframe: 7 weeks
Engine: Unity2D
Language: C#
Flocking Rules
Flocking rules are mathematical functions describing movement of an AI agent in relation to others around it. Combining several flocking rules results in emergent behaviour when multiple agents are placed near each other. I used eight flocking rules in this project:
- Cohesion: steers each agent towards the average position of its neighbours.
- Alignment: adjusts each agent's velocity to match the average velocity of its neighbours.
- Separation: makes agents stay some minimum distance apart to avoid collisions.
- Lifespan: determines the duration of the current simulation run.
- Tendency Towards Location: "attracts" agents to the cursor position when the left mouse button is held.
- Environment Retention: keeps agents within the screen's bounds.
- Obstacle Avoidance: makes agents avoid user-placed obstacles in the environment.
- Max Speed: prevents agents from travelling at arbitrarily fast speeds.
The influence of these rules, alongside agents' visual range and view distance, are all adjustable using sliders.
How do they Move?
The influence of each flocking rule is a numerical value corresponding to the weight of each rule in physics calculations. Physics are calculated for each agent, rule-by-rule, to obtain a net force vector used to update each agent's on-screen movement for that frame.
With this approach (and ignoring gravity and collisions), I avoided Unity's physics and rigid body system altogether, improving performance.
Interactivity
Aside from user-defined obstacle placement and making agents flock to the user's cursor while the left mouse button is held down, several interactive and customisable elements are featured to facilitate creation of generative art:
- the influence of variables and rules can be adjusted using sliders;
- the colour of agent trails can be customised;
- the theme/colour palette of the simulation can be switched; and
- the visibility of placed obstacles can be toggled on/off
Results
Results are mixed. Based on supplied parameters, various types of flocking behaviours can be observed, but it can sometimes be hard to see the individual effects of each flocking rule, especially when there are more than 4-5 simultaneously affecting an agent's velocity.
This could be because of the finicky nature of the flocking rules themselves. Some rules have a more noticeable effect on resultant behaviour, and so certain rules can overpower others. Fine-tuning the ranges of weights each rule can be adjusted to, alongside allowing 4-5 flocking rules to be applied at any one time maximum, might help make the effects of individual rules more pronounced.
Try it Out!
Installation Instructions
No installation required; this is an online WebGL build! Simply click the button below to be redirected to the application in-browser. Make sure to enable fullscreen mode for the best experience!
This build runs best on Chrome and Edge browsers.
Link to Build
Link to Repo
Click the button below to access the project's repository:
Boids Interactive Repo
Link to Paper
Click the button below to access the research paper associated with this project:
Boids Interactive paper