Hold Your Breath: Horror FPS Kit with Flashlights, Scripted Scares and Stalkers
- ..
- .metadata106 B
- README.md17.5 KB
- Stalker.component
- StalkerLair.component
- anim_attack_anims
- anim_crawl_anims
- anim_death_anims
- anim_grab_anims
- anim_hurt_anims
- anim_idle_anims
- anim_screech_anims
- anim_shamble_anims
- api.module
- body.module
- brain.module
- core.module
- creature_skin.material
- diver_brass.material
- diver_canvas.material
- how-to-add-a-monster-that-hunts-the-player-by-sound-and-light.guide
- kinds.module
- package.yaml1.6 KB
- snd_lurker_hiss.soundClip
- snd_pursuer_attack.soundClip
- snd_pursuer_breath.soundClip
- snd_pursuer_clicks.soundClip
- snd_pursuer_death.soundClip
- snd_pursuer_hurt.soundClip
- snd_pursuer_screech.soundClip
- snd_pursuer_step.soundClip
- snd_shambler_death.soundClip
- snd_shambler_groan.soundClip
- snd_shambler_hurt.soundClip
- snd_shambler_step.soundClip
- snd_vent_crawl.soundClip
- sounds.module
- stalkerKitTests.testSuite
README.md
stalkerKit 1.0.2
Horror monsters that hunt the player. Put a Stalker on a character, pick a kind with one field, and it listens, follows your torch light, stalks you out of sight, hunts where it heard you, searches where it lost you, chases, attacks, and slips back into a vent when it is hurt or caught in your light too long, to come back later. Five kinds ship (pursuer, shambler, lurker, light-shy, blind hunter); each is plain data a designer tunes without code.
stalkerKit is built on aiKit (brains, senses, memory), navKit (movement) and SecondWind (health and damage). That means weaponsKit weapons hurt the monsters with no extra wiring, and every aiKit character hears the same noises.
Install
Install stalkerKit.package from ZeroMind (search "stalkerKit" or "monster that hunts the player by sound and light"). It needs aiKit 1.4.0 or later in the world (aiKit brings navKit, SecondWind, Lifeline and MatchFlow); 1.4.0 is the release that adds carried lights (AI.setCarriedLight), which is how a torch gives the player away.
First example
In code that runs in play on the host, once the level's colliders exist, with a navKit map baked over the floor (require("~navKit.api").bake({ kind = "grid" }), a frame or more after the walls are spawned; see Known limits):
local Stalkers = require("stalkerKit.api")
-- a vent the pursuer can slip into (stand it on the floor in front of the opening)
Stalkers.addLair({ -56, 0, -404 })
Stalkers.addLair({ -4, 0, -456 })
-- the hunter and a drowned diver
local pursuer = Stalkers.spawn("pursuer", { -25, 0, -412 })
local diver = Stalkers.spawn("shambler", { -20, 0, -430 })
-- your game hands over its own: here a stand-in player body, its camera's forward and a shot
local playerBody = entity.spawn("playerBody"); playerBody.position = vector.create(-25, 0, -420)
local cameraForward = vector.create(0, 0, -1)
local shooterBody, shotPosition = playerBody, vector.create(-25, 1.5, -420)
-- weapon fire, doors and torch clicks give the player away
Stalkers.hearNoise(shotPosition, "gunshot", shooterBody)
-- a torch kit says how visible a player is (0 dark .. 1 torch on) and where the beam points
Stalkers.setPlayerLight(playerBody, 1, cameraForward)
-- a tension director reads how close the danger is
local danger = Stalkers.threatFor(playerBody) -- 0..1
Stalkers.on("noticed", function(e) print(e.entity.name, "is after", e.target.name) end)
Or place it by hand: a synced entity with stalkerKit.Stalker { kind = "pursuer" } (it adds the aiKit Brain itself), and stalkerKit.StalkerLair on the entities in front of your vents.
Kinds
| kind | look | senses | what it does | dies? |
|---|---|---|---|---|
pursuer | tall, gaunt, too-long limbs and claws, pale wet skin, barnacle crusts, an eyeless elongated skull with a slit of needle teeth | sees only lit things (beyond 4.5 m), 24 m, 140°; hears 1.7× as far; notices a torch beam in its face from 16 m and a lit torch inside its cone from 36 m | the main hunter: hears shots, running, doors, torch clicks and thrown things; stalks out of sight at 8-14 m for up to 9 s, commits when you come close, shine your torch on it or it has watched long enough; chases, attacks (28 dmg); hunts and searches the last-known spot; after 5 s lit, 22% health lost in 6 s or 22 s of chasing it screeches and runs to the nearest vent, crawls in, heals for 16-30 s and crawls out of the vent nearest a player | no: at 20% health it retreats and heals |
shambler | a drowned diver: bloated, in a rotting canvas suit, cracked brass helmet with a swollen face behind the porthole, lead boots, kelp | 9 m sight, poor hearing (0.8×), remembers for 40 s | slow (0.85 / 1.55 m/s), relentless (gives up after 12 s unseen), grabs and bites (34 dmg, slow), 360 HP, shrugs off small hits | yes |
lurker | a darker, crouched pursuer thick with barnacles | 16 m, all round | waits motionless where you put it; moves only while no player is looking at it (freezes in your view); lunges from 3 m with a hiss; after a short chase melts back into a lair or the dark | yes |
lightshy | pale pink skin with glowing blue spots on its skull | 18 m, notices beams | circles at 5-9 m at the edge of your light; a beam or strong light on it for 1.2 s makes it recoil to the nearest dark; strikes the moment you stand in darkness | yes |
blind | grey-green, eyeless, a huge barnacle-crowned skull | hearing only, 2.2× (a walking footstep from 11 m) | goes where it heard; walk slowly (silent), throw something, or stand still | yes |
Body styles (stalker.body, one field)
Every kind's look is its stalker.body knob, so any kind can wear any body: pursuer, shambler, lurker, lightshy, blind, and drowned.
drowned (new in 1.0.9): a tall (2.55 m), gaunt, long-limbed, hunched figure draped in river weed and dripping silt. Dark olive-brown silt skin that stays matte under a torch (roughness 0.88, metallic 0, almost no clearcoat), a dark elongated skull, long dark claws, no barnacles and nothing that glows. About 40 strands of weed hang from the head, shoulders, elbows, hands, back, hips and thighs; each hangs from gravity whatever the pose, bends in two segments and sways in Body.update (more while it moves), and a pool of 10 silt drops falls from the strand tips and is reused (parked while the body is hidden). Use it on any kind:
Stalkers.tuneKind("pursuer", { stalker = { body = "drowned" } }) -- every pursuer
Stalkers.defineKind("riverman", { base = "pursuer", stalker = { body = "drowned", sounds = "shambler" } })
Every kind is an aiKit preset (stalker.<kind>) plus a stalker table of knobs. Change them for the whole game:
local Stalkers = require("stalkerKit.api")
Stalkers.tuneKind("pursuer", { stalker = { stalkTime = 15, hideTime = { 40, 60 } }, preset = { move = { run = 5.6 } } })
Stalkers.defineKind("hound", { base = "pursuer", label = "Hound", preset = { move = { run = 7 } }, stalker = { stalk = false } })
Knobs (stalker table)
| knob | pursuer | meaning |
|---|---|---|
drawnToLight | 1 | 0..1: a lit torch inside its eyes' cone is a lead out to 36 m × this |
lightShy | 0 | light level where it stands that it cannot bear (0 = never) |
litTolerance | 5 | seconds in a beam / strong light before it breaks off (0 = never) |
attackOnlyInDark | false | will not close in while the prey stands in light |
stalk, stalkRange, stalkTime, commitRange | true, {8,14}, 9, 5 | keep its distance out of sight before committing |
huntRun | true | runs to loud leads (gunshot, door, shout) |
chaseTimeout | 22 | seconds of chase before it slips away (0 = never) |
searchTime, vanishAfterSearch | 14, 0.5 | how long it searches; the chance it then slips into a lair |
retreats, hurtRetreat | true, 0.22 | breaks off after losing this share of health within 6 s |
dies, floor | false, 0.2 | false: never drops under floor health; retreats and heals instead |
hideTime, returnNear | {16,30}, true | seconds in the lair; come out of the lair nearest a player |
lurk, freezeWhenWatched, springRange | false, false, 3 | ambusher behaviour |
flinch, staggerAt | 0.3, 30 | seconds a hit stops it; damage in one hit that staggers it twice as long |
grab | false | slow grab-and-bite attack |
breathEvery, screechOnNotice | {4,7}, true | feel |
body, sounds | pursuer | which body and sound set it uses |
API (local Stalkers = require("stalkerKit.api"))
| call | what it does |
|---|---|
Stalkers.spawn(kind, at, opts?) -> entity | Spawn a synced stalker (opts: name, yaw, lairGroup, route, active). |
Stalkers.addLair(at, opts?) -> entity | A vent / dark hole at a position, or on an entity (opts: group, kind = "vent" or "dark", yaw). |
Stalkers.sendTo(e, pos, { run }) | Send it to look at a spot. |
Stalkers.retreat(e) | Break off now and slip into a lair. |
Stalkers.appearAt(e, pos, { face }) | It crawls out at a spot, then hunts toward the nearest player. Cancels a retreat still under way and releases a holdHidden. Orders sent in the same moment are all seen, in order; the last that changes what it does wins. |
Stalkers.holdHidden(e, on) | Keep it in its lair until released. |
Stalkers.setKind(e, kind), Stalkers.setActive(e, on) | Switch kind; switch its brain off/on. |
Stalkers.hearNoise(pos, loudness, source?, kind?) | A noise: metres or a name (gunshot 35, slam 22, throw 16, door 14, run 11, impact 10, click/torch 6, footstep 5). source = who gives themselves away. Goes through aiKit's noise bus. |
Stalkers.setPlayerLight(player, level, beamDir?, { range, cone }) | A torch kit reports a player's light (0..1) and beam; call it on the player's own peer. |
Stalkers.playerLight(player) | The light as the monsters know it. |
Stalkers.threatFor(player) -> 0..1 | Danger for a tension director: nearest stalkers, what they do, whether they are after this player. Every peer. |
Stalkers.list(), Stalkers.info(e), Stalkers.nearest(pos, { visible }) | What is out there. |
Stalkers.kindNames(), kind(name), defineKind, tuneKind | The kinds as data. |
Stalkers.on(event, fn) -> connection | Events (below); call the connection or :Disconnect() to stop. |
Events
| event | payload | fires on |
|---|---|---|
state | entity, state, from, detail, state is idle, stalk, hunt, search, chase, retreat or attack; detail is the brain's own state (lurk, creep, recoil, vent, hidden, appear...) | every peer |
noticed | entity, target | every peer |
lost | entity, target | every peer |
attacked | entity, target, kind (attack, grab) | every peer |
hurt | entity, amount, by | the peer running it |
retreated | entity, lair | the peer running it |
appeared | entity | the peer running it |
died | entity, by | the peer running it |
noise | position, radius, kind, source | the peer that called hearNoise |
* | { event, data } | all of the above |
Fighting them
Their health is SecondWind's, so weaponsKit's hitscan, projectiles and melee hit them (weaponsKit hits collider-less characters as a capsule; the Stalker sizes it to the creature: 2.3 m for the pursuer, 0.5 m wide for the shambler). A hit flinches them; one of 30+ damage staggers. The pursuer cannot be killed by default (dies = false): it screeches and retreats to heal, so ammo buys time, not safety. The shambler dies after about 360 damage. Ammo is the level's job: keep it scarce (a handful of rounds per encounter) so running, hiding in the dark and turning the torch off stay the better answer.
Multiplayer
The host (or the entity's owner) runs the brains through aiKit; every peer builds the same body from the synced kind and animates it from the synced pose and one-shot counter, and plays the sounds locally, so nothing but a few fields crosses the network. Any player can be hunted. Torch reports go from each player's peer to the host through aiKit's carried-light channel. Scripted orders (sendTo, retreat, appearAt, holdHidden) work from any peer.
Performance
Each stalker is one aiKit brain (senses 10×/s, thinks 15×/s) plus a skinned body with ~60-110 small parts and an AnimGraph ticked in script. A pursuer is roughly one aiKit character plus one animated body; two or three on screen are fine on a tablet. Parts cast no shadows where they are small. Lower AI.config.senseRate / thinkRate for weaker devices.
Known limits
-
Nothing reports your torch to the monsters unless something calls
setPlayerLight. horrorKit does it for flashlightKit's torch; with flashlightKit alone, callStalkers.setPlayerLight(body, Torch.visibility(nil))on the player's own peer a few times a second. -
Switching the torch off does not shake a pursuer that already has you. Measured in an empty world, twice: standing still in the dark with no lead, it never found the player (idle at 18 to 21 m for 20 s); with the torch on it noticed at about 14 m, stalked and caught the player within about 10 s; switching the torch off then (during the chase, or after sending it to a lair) did not lose it: it went to where it last knew the player and, since it sees an unlit player inside
darkRange(4.5 m), found them and kept attacking. Put distance, a door or a hiding place between you before you go dark. -
Bodies are a re-proportioned stock rig. Mesh generation was out of quota when this was built, so every creature is the engine's rigged humanoid stretched, re-skinned and dressed with procedural parts. A generated or imported rigged creature can replace it in
stalkerKit.body(Body.STYLES). -
A hidden stalker keeps its hit volume at its lair. Shots into an empty vent can still hit it.
-
Lurker "watched" check uses where each player faces (the torch report's beam when there is one, else the avatar's turn), not the exact camera.
-
Bake the navKit map after the level's colliders exist: a grid map baked in the same frame the walls were spawned has no walkable cells and every stalker stands still ("unreachable").
-
Vents are entry points, not paths: a stalker vanishes into one and comes out of another; it does not crawl through ducts.
Tests
tools.use("tests", "run", { suite = "stalkerKit" }) (edit mode): kinds and presets, the API, hearNoise reaching aiKit's bus, events, threatFor, and a play test where a pursuer hears a gunshot and goes to it.
Version history
- 1.0.0: First release: five kinds, the stalker brain, the Stalker and StalkerLair components, bodies, generated animations and sounds, the api with noise, light, threat and scripting hooks, a guide and a test suite.
1.0.2
README only: how to bake the navKit map in the first example; that the torch reaches the monsters only through setPlayerLight (horrorKit or your own code); what a pursuer does when you go dark mid-chase.
1.0.1
Bodies use lit materials, so a monster in a dark room is invisible until a light finds it. Overhead health bars are off by default (healthBar field). setActive reliably wakes and stills a monster. Declares aiKit 1.4.0 and its other dependencies with versions.
1.0.10
A Stalker whose kind the game defines after it woke now waits for that kind instead of failing. A joining player's engine receives the creature before the game's start code defines its own kinds, and the Stalker used to hand aiKit the unknown preset at once, which threw ("aiKit.addBrain: unknown preset 'stalker.<kind>'") and disabled the component for good on that player's side. Now its brain and body are built as soon as the kind exists (Kinds.has(kind) is new). New test: "waits for a kind defined after it woke". Found in Low Water's co-op.
1.0.9 (stalker.body = "drowned"): tall, gaunt, long-limbed and hunched, draped in swaying river weed, dripping silt, matte dark silt skin, nothing glows. appearAt now always cancels a retreat in progress: orders queue until the brain next thinks instead of the later one overwriting the earlier, a non-retreat order clears the retreat and frees the lair it was heading for, and appearAt releases a holdHidden (a game no longer needs to switch the brain off and on to bring it out). New test "appearAt cancels a retreat in progress".
1.0.8
Correction to 1.0.7: its wait for the sky light does not prevent the occasional 6 "camera texture not found" errors during the in-play test, so it is removed. Those errors come from the engine, not this kit: switching into play makes the sky light build six internal capture cameras, the test runner's leftover sweep removes them when the test ends, and the sky light later draws through the removed cameras (reported to ZeroMind). The tests pass either way; a plain install and play logs none. No changes outside the tests and README.
1.0.7
The tests leave no camera errors: the play test restarts the sky light, and each test now ends only once the sky light has finished its capture, so the runner's cleanup never removes capture cameras with a picture still queued. No changes outside the tests.
1.0.6
The tests remove everything each test (and the monsters it spawned) left behind and wait for previews a fresh install is drawing, so a passing run leaves no errors. The second README example requires the API itself and runs on its own. No changes outside the tests and README.
1.0.5
Declares SecondWind 1.4.8, the version stealthKit 1.0.22 brings, so a world with both kits runs one SecondWind. No code changes; stalkerKitTests 7/7 on 1.4.8.
1.0.4
Declares SecondWind 1.4.7, the newest SecondWind release, which is what an install beside stealthKit 1.0.20 places (it stated 1.4.8). No code changes; stalkerKitTests 7/7 on 1.4.7.
1.0.3
Bodies keep their surfaces again on the current engine: each part's roughness, clearcoat and glow (the pursuer's eyes and spots, the diver's porthole) went to Model:setMaterialProperties, which now writes the shared material and failed on the kit's runtime materials (hundreds of warnings, flat parts). Parts and skins now get materials of their own with those values, made once per look; no shared material is ever repainted. README: the first example defines the player body, camera forward and shot it uses.