Fear-driven movement
By Robin Dowling ยท 3 months ago
Survival in nature involves avoiding danger. In the simulation, organisms needed a way to recognize and flee from threats, specifically, larger organisms that might be dangerous.
I implemented a fear-driven behavior where organisms detect nearby organisms significantly larger than themselves. If a detected organism is at least 1.5 times their mass and from a different species, the smaller organism has a high chance of fleeing. If the larger organism is from the same species, there's a smaller chance, about 7.5%, to flee, modeling occasional avoidance of dominant members within a species.
The system filters out organisms that aren't actually threatening. Pregnant organisms aren't perceived as threats, they're vulnerable. Low-energy organisms aren't threatening either, they're weak. And family bonds override fear entirely: organisms never flee from their parents or children, regardless of size difference.
When an organism decides to flee, it calculates the centroid of all nearby threats and moves in the opposite direction. The system uses weighted direction selection to maintain momentum - organisms don't just move randomly away, they continue fleeing smoothly in a consistent direction.
Fear also creates a form of memory. When an organism flees from a position, that position is added to its recent position history with a penalty. This prevents the organism from immediately wandering back into the danger zone after fleeing. The penalty decays over time as the position ages out of the organism's memory.
The result is visible in the simulation. Smaller organisms maintain distance from larger ones. Larger organisms naturally dominate areas. Groups stay cohesive because smaller members avoid straying into territories occupied by larger organisms of other species. There's no explicit territorial behavior coded, it emerges from individual fear responses.
It's a simple threat-detection system, but it creates complex spatial dynamics across the simulated ecosystem.