Building Laya: an AI companion that actually follows you
There is a particular kind of mod that gets made for every new survival game: the companion. It spawns a friendly mob next to you, it walks about, and after about four minutes you notice it is not actually doing anything. It does not keep up. It does not help. It walks into a wall while you are being chased by something that has opinions.
Laya Companion started because I wanted the opposite of that. Not a cosmetic follower with a personality written in a config file, but something that reads the situation I am in and acts on it.
The part everyone underestimates
The tempting approach is to start with the intelligence. Wire up a model, feed it the world state, let it decide. That is genuinely the easiest part, and if you build it first you will spend weeks feeling productive while the mod is unplayable.
The real problem is latency and trust. A companion that decides well three seconds late is worse than a companion that decides badly instantly, because you cannot plan around it. Every moment it hesitates, you are standing still waiting to find out whether help is coming.
What actually makes it feel alive
1. Reaction beats in-game
The single biggest quality jump was not smarter decisions. It was faster acknowledgement. The moment a threat appears, Laya turns toward it. The turn is cheap and needs no deliberation. By the time the actual choice resolves she is already facing the right way and already moving, so the deliberation is invisible.
2. State you can read at a glance
If the player has to guess why the companion did something, the companion feels broken even when it is correct. Every action surfaces its reason: a marker, a stance, a change in how she moves. Nothing happens for no visible cause.
3. Consistent personality under pressure
It is easier to trust a companion with a clear bias, one that always prefers to protect over to pursue, than one that is optimal. Optimal behaviour on average looks erratic. A readable bias looks like a personality.
4. Memory that is small and honest
She remembers who helped, who hit her, and where she was told to stay. That is roughly the entire memory model, and it is enough. A large memory you cannot inspect becomes something the player cannot predict.
The technical shape
The companion is built around a tight loop:
observe → score candidate actions → commit to one
↑ │
└──────────── replan on change ←─────────┘
Observation is cheap and runs every tick. Scoring runs at a lower frequency, and only when the situation has actually changed in a way that matters. A new threat, a lost target, a health threshold crossed. Between changes the committed action continues. That is what removes the stutter.
The AI layer sits above this, not inside it. It receives a summary of what is happening and can adjust weights and intent, but it never runs the tick loop. The tick loop is deterministic, fast, and works fine when the model is unavailable.
What I would tell someone starting their own
- Build the dumb version first. Follow, stay, attack, flee, gather. If that already feels good, the intelligence is a multiplier. If it does not, no amount of reasoning will rescue it.
- Budget your latency before you write anything. Decide how long a decision may take, then design so nothing visibly waits on it.
- Never let the player wonder. Every inexplicable action costs more trust than a wrong action.
- Make the fallback boring on purpose. Boring and reliable beats clever and flaky.
Where it goes next
Laya is at a point where the loop is solid and the interesting work is in expression: making the same competence look different depending on the player's style. A player who fights wants a companion that fights alongside them. A player who builds wants one that stays out of the way and brings things back.
That is not a smarter model problem. It is a taste problem, and it is much more fun.
If you play Hytale, the mod is up on CurseForge, and there is a page with the current stats and screenshots on this site.