Wilden Dawn

Movement momentum and memory

By Robin Dowling ยท 3 months ago

Organisms were oscillating. They would move one position toward food, then immediately move back the next tick, move toward a mate, then reverse course. The movement logic evaluated each tick independently, with no memory of where the organism had just been or which direction it was already moving.

This ping-ponging created unnatural, jerky movement that made the simulation feel mechanical rather than alive.

I implemented two mechanisms to solve this. First, directional momentum. The existing momentum system that weighted random movement to continue in the same direction was extended to all movement types. When an organism moves toward a goal or away from a threat, it now prefers to continue in roughly the same direction rather than making sharp turns. The weighting is exponential: continuing straight ahead is most likely, adjacent angles are less likely, and reversing direction is least likely.

Second, short-term position memory. Each organism now tracks the last 8 positions it visited in a circular buffer. When evaluating potential moves, recently visited positions receive penalties that decay exponentially. The most recent position gets about a 70% penalty, making it very unlikely the organism will immediately return there. Older positions have weaker penalties, eventually aging out of memory and becoming acceptable again.

These penalties are probabilistic, not absolute blocks. An organism can still return to a recent position if the situation demands it, if food is there or if fleeing danger requires it, but there's a strong behavioral preference to keep moving forward rather than backtracking.

The combination creates movement that feels organic. Organisms trace continuous paths, avoid constantly reversing course, and exhibit spatial awareness of where they've recently been. They still respond appropriately to goals and threats, but they do so with momentum and memory rather than instant reactions.

The change was technically and mathematically straightforward, a circular buffer and some weighted probability adjustments, but the behavioral impact is substantial. Movement looks and feels natural now.