# The thing that follows the light: a stalker as a state machine

> Ravenhush's enemy is a plain state machine and a director, tested in Node. How it hunts, why the flashlight draws it in, and how the on-screen advice stays true.

Canonical page: https://andersonmancini.dev/blog/ravenhush-presence

Published: 2026-11-25 · 5 min read · Tags: game-dev, ai, javascript, horror, testing

The enemy of [Ravenhush](https://andersonmancini.dev/blog/ravenhush.md) is something you never see whole. It is also, in code, a very small thing: a state machine and a director, with no Three.js in it, no audio and no DOM. It decides when it comes, where it is and how much dread it puts on you. Everything else only reads from it: the renderer, the lens, the flashlight and the sound.

## Five phases

```text
DORMANT -> STIRRING -> STALKING -> OVERWHELM -> RECEDING -> DORMANT
```

Each phase is something the player can perceive, and that was the point of choosing them.

- **Stirring.** It is far and coming. The crows go quiet and the wind drops. That is the only warning you get.
- **Stalking.** It is near and following. The torch sputters, whispers come from its side and the lens starts to warp.
- **Overwhelm.** It is on you. Flicker, a whine in your ears, barrel distortion and radial blur at their worst, and the pale light in the north lies.
- **Receding.** It withdraws. The dread drains over several seconds and the crows come back.

Because the module is pure, the renderer, the audio and the fog all read the same three numbers: `phase`, `bearing` and `dread`.

## The director

A second piece schedules the encounters, and its rules are data:

```javascript
const DEFAULTS = {
  firstAfter: 80,            // s of play before the first encounter
  cooldown: [ 150, 230 ],    // s of quiet between encounters
  scripted: [ 260, 540, 770 ], // metres along the route: one is due once the player passes each
  maxEncounters: 8,
  spawnDistance: 62,
  stirringTime: [ 9, 14 ],
  stalkRange: 30,
  overwhelmRange: 11,
  dwell: [ 7, 11 ],          // s it stays on top of the player
  recedeTime: 9,
  loseTrack: 7,              // s of silence and darkness before it loses the player
  giveUpRange: 20,           // overwhelm -> receding if the player opens this much distance
};
```

It appears about 60 m behind you, never during the first 80 seconds, never close to the start and never while you are reading a paper. Some encounters are scripted along the route and the rest are random, 150 to 230 seconds apart, at most eight in a game. It never comes closer than about 5.5 m.

## It follows what it senses

The player's agency is in what the presence can sense. Running is loud, but it opens distance, and past a gap of 20 m it gives up. A lit torch is enough to be found. Standing still in the dark is not: after 7 seconds of silence and darkness it loses you and drifts away. Crouching halves the noise you make and, in the dark, makes it lose you a third sooner.

The self-test is a list of promises about all this. In no encounter is there anything in the first 80 seconds. The phases come in order. It never gets inside 5.4 m. The overwhelm really is overwhelming, with the dread reaching at least 0.85. A walker at 4 m/s is followed, with the gap growing by less than 6 m in 15 seconds, while a runner at 8 m/s leaves it more than 30 m behind in the same time. Stillness in the dark makes it lose the player, and crouched in the dark it does so more than a second sooner than upright.

## The light calls it

This is the design decision I changed my mind about. In the first version a beam held on a Grey for 1.2 seconds sent it away: the light was safety. I wanted the opposite. The flashlight should not drive them away, it should call them. Put the light out and get down for them to go. Keep walking lit and they keep following, faster and faster.

So now, while the presence hunts with the torch on, its pace grows up to 1.4 times over 10 seconds of light, and it cools at half that rate in the dark. While you are lit, the overwhelm's dwell runs at a quarter of its pace: it stays on you. The Grey that you can see, at the edge of the beam, follows the same rule:

| | Result |
|---|---|
| Pace with the torch on | from 1.4 m/s to 8.6 m/s over 10 s of light (you walk at 6 and run at 10) |
| Simulated from 15 m, a lit walker | taken in about 18 s |
| Simulated from 15 m, standing in the light | taken in about 5 s |
| 3 s lit, then down in the dark | it goes 9 m off |
| In the browser, torch left on | it showed at 13.6 m and took the player 4.5 s later |
| In the browser, hiding at once | it stood still and was gone in 4.5 s |

## The advice has to be true

When the presence stalks you, two short lines come up in the middle of the screen: "Light off. Get down.", and once you have, "Don't move." They are the game's advice in that moment, so they must be true. The self-tests prove that doing what they say makes the presence lose you, and makes the Grey go. If I ever change how the presence senses or how the Grey hunts, those tests have to stay green, or the game would be lying to the player.

## Fear is the only damage

Nerve and lives are a pure module too. Only fear hurts you, and its drain starts at the same dread level where the whine begins in the sound. Running costs a little and never takes the bar below 15% by itself: only fear can make you faint. The settings have Fear on Normal, Gentle or Off, and "Reduce effects" is visual only, it does not change the drain. There is also a button called Take a breath: the world goes still, the encounter ends, a quarter of your nerve comes back and a circle swells and eases until you are ready.

## Why it is pure

The unglamorous part is that I can test the enemy without a GPU, without a browser and without playing. The presence, the Grey's hunt, the nerve, the hiding advice, the guidance and the world are all plain modules with a self-test each, run in Node. About 125 of them pass today. When I want a scarier forest, I change numbers in a table and run a test, not a build.

Ravenhush is free in the browser at [ravenhush.vercel.app](https://ravenhush.vercel.app/), and the project page is [here](https://andersonmancini.dev/projects/ravenhush.md).

## Related projects

- [Ravenhush](https://andersonmancini.dev/projects/ravenhush.md) — Free sci-fi horror game for the browser
