Fly Circus — The Living Simulation
README.md
FlyAgent
One living Fly Circus creature.
Attach it to an entity the scene's build has stood a fly body under (see
flyBody). It owns a spiking brain, reads the world into it, reads motor
commands back out, moves itself through real collision, and poses the body.
What it is
Not a fake. Nothing here decides a behaviour and then displays a number that agrees with it. The senses are currents into named circuits, the behaviour is whatever those circuits do about it, and the inspector reads the same rates the movement came from.
Simulated: the neural dynamics (leaky integrate-and-fire with synaptic delays, inhibition, refractory periods and reward-gated Hebbian plasticity); the drives (hunger, energy, stress, curiosity), which are real state that rises and falls; the movement, which obeys the scene's actual colliders by raycast and sphere-cast; and the food web, which is depleted by eating.
Approximated: the sense organs are simplified — "odour" is distance to the nearest food site rather than a diffusion field, and "vision" is a proximity and approach test rather than an image. The brain is a few hundred neurons, not a fly's hundred thousand. Biologically inspired; not a model of a real animal.
The loop, once per frame
- Drives — hunger rises, energy falls with exertion, stress decays at the species' nerve.
- Senses — the nearest food as a sustained odour current, a looming visitor as a vision current, another fly as touch. Each goes into its own circuit.
- Brain —
net:update(dt)in bounded fixed steps. - Decide — the mode comes from the brain's own output scaled by the species' temperament, plus memory: a place it has eaten before is only recalled when the memory circuit is actually firing.
- Move — steer toward what won, against real colliders, inside a home range.
- Pose and place — wings, legs, proboscis and the transform.
- Signal — occasionally, and only when a need is really true of the fly.
Modes are explore, seek, eat, flee, rest, social and return.
Public fields
species, displayName, seed, chatiness (silent/rare/natural/social),
hunger, energy, stressLevel, activity, abstracted, senseRange,
speaking. The director drives these directly.
Methods
| Method | What it does |
|---|---|
label() | the name this fly answers to |
rename(newName) | rename it; empty returns it to its species name |
doing() | what it is doing right now, as one word |
readout() | everything its brain is doing: region rates, drives, position, home, memory, what it has learned |
setDrive(which, value) | set hunger, energy, stress or dopamine outright |
reward(amount) | a dopamine burst — it learns, and calms down |
calm() | clear its stress and let it rest |
forget() | erase its memories and reset the brain without changing its wiring |
Two things that were bugs worth remembering
awake runs before the entity's children exist. The fly's body IS those
children, so binding the rig in awake finds an empty tree. Binding happens in
start(), and update retries — which is also what repairs the rig after a
hot-reload, when the module's memory of it is gone but the entities are not.
A fly's home must not move. It is private and serialised, fixed once where
the creature was created. Held in a public field it drifts with the fly; set in
awake it is re-captured at whatever position the fly held the next time the
component reloaded — which is how a creature ends up with its home pinned to the
south edge of the world and stays there for ever.