Behaviors

How GOKIs's critters move — threat response, wall following, and the entomology research behind it.

GOKIs’s critters are not following a canned animation loop. Every frame, the GPU evaluates each critter’s state, picks a behavior, and updates position and velocity. The model is grounded in published research on cockroach escape behavior.

What triggers an escape

The mouse cursor is treated as a predator. Each critter measures the distance to the cursor every frame:

  • Threat radius: 180 pixels. Anything inside this radius is a threat.
  • Two-stage response: weak stimuli trigger an alert pause (the critter freezes and assesses). Strong stimuli trigger an escape.

This two-stage model comes from Camhi & Nolen’s 1981 work on cockroach giant fibre responses.

How the escape moves

When a critter escapes, it does not pick a random direction. It chooses from four preferred escape angles relative to the threat:

AngleMeaning
90°Perpendicular dash
120°Diagonal away
150°Sharp turn away
180°Straight retreat

Roughly 90% of escapes are “away” responses; the remaining 10% counter-intuitively head toward the threat at a steep angle. Both numbers match the observations in Domenici et al. (2008).

Wall following

Cockroaches feel safer when they are touching something. GOKIs models this with thigmotaxis (innate preference for wall contact, varied per individual). Critters that are not currently fleeing tend to:

  • Drift toward the nearest screen edge (or text boundary, see below).
  • Move along edges once they reach them.
  • Linger near corners.

Each critter has its own personality — three values (thigmotaxis, boldness, activity) sampled from a Gaussian distribution at spawn time. So no two critters behave quite the same way, and the population stays interesting at any scale.

Daily vs survival behaviors

The internal state machine separates two kinds of behavior:

  • Survival behaviors — ALERT (freezing) and ESCAPE. Triggered by threats. Always win over everything else.
  • Daily behaviors — REST (recovering fatigue), WALL_FOLLOW (drifting along edges), EXPLORE (wandering in open space), SEEK_WALL (heading toward an edge). Selected by utility scoring when no threat is near.

The utility score balances current fatigue, contact need, recent history (you tend to keep doing what you were just doing), and individual personality.

Text boundary

A signed distance field generated from the word “GOKIs” is layered on top of the screen bounds. Critters treat the outline of the text as a wall too, so they cluster inside the letters when idle. Toggle it off from the menu bar (Show Text Boundary) if you prefer plain rectangular screen edges.

References

  • Camhi, J. M. & Nolen, T. G. (1981). Properties of the escape system of cockroaches. Journal of Comparative Physiology.
  • Domenici, P. et al. (2008). Cockroaches keep predators guessing by using preferred escape trajectories. Current Biology.