Concept and Inspiration
My concept started from noticing that steering behavior looked very similar to moving ants. That gave me the idea to build an ant colony cross section simulation where ants travel between underground burrows and the surface like a terrarium. The simulation uses seek behavior and path following to create ant-like movement patterns.
Code Highlight
The part I am most proud of is the state machine in my Ant class. It coordinates each ant going to the surface, roaming, returning to the path, going back to the burrow, waiting, and repeating. Adding the returnToPath state was especially important because it fixed the issue where ants were cutting through the ground instead of reconnecting to the path at the surface first.
if (this.state === "roamSurface") {
if (!this.roamTarget || p5.Vector.dist(this.pos, this.roamTarget) < 16) {
this.pickNewRoamTarget();
}
this.seek(this.roamTarget);
if (millis() >= this.roamUntil) {
this.state = "returnToPath";
}
return;
}
if (this.state === "returnToPath") {
const overgroundJoin = this.path.getEnd();
this.seek(overgroundJoin);
if (dist(this.pos.x, this.pos.y, overgroundJoin.x, overgroundJoin.y) < 20) {
this.state = "returnToBurrow";
}
return;
}
Embedded Sketch
Milestones and Challenges
Stage 1: One path, one ant
I started with one ant following one path to verify that seek and basic path following were working correctly.
Stage 2: One path, multiple ants

After confirming the basic behavior, I added multiple ants on the same path to test how the movement looked in a colony-like flow.
Stage 3: Multiple paths, multiple ants per path

I expanded the colony to multiple burrows and assigned ants to specific paths so each group had a consistent route to and from the surface.
Stage 4: Ground/grass visuals and roaming fix

I added the dirt and grass cross-section layout and introduced a roamSurface state for surface movement. A key challenge was that ants sometimes traveled through the ground when returning. I fixed this by adding a returnToPath state so ants first reconnect at ground level and then follow the tunnel path back down.
Reflection and Future Improvements
Right now, over ground, the ants still look like they are flying rather than staying fully attached to the ground surface. A future improvement would be to constrain or project overground motion to a ground contour so movement feels more realistic. I would also like to continue the ant colony idea further, or expand this into a larger ecosystem simulation with multiple interacting species and behaviors.