perception.module
README.md
perception
What an observer can see and how fast it notices. Pure maths, no engine.
An observer stands at (x, y, z) facing (fx, fz) on the ground plane and is of a kind the config describes
(range by light, half-angle, a near range that works whatever way it faces, and optionally how far up and
down it looks). The host supplies the one thing geometry cannot: whether the line between the two is blocked
(`hasLine`, from a physics ray or anything else).
local Perception = require("~.modules.perception")
local seen, distance = Perception.inView(kindCfg, light, ox, oz, fx, fz, tx, tz) -- flat ground
local seen, distance = Perception.inView3(kindCfg, light, { x, y, z, fx, fz }, { x, y, z })
-- with heights: distance is the straight line; kindCfg.vertical = { up, down } (degrees) limits how steeply
-- it looks (someone on a roof is not seen by a guard with up = 35 standing at the wall's foot)
local rate = Perception.fillRate(cfg, "guard", {
distance = distance, inView = seen, hasLine = true, light = 1,
act = "wanted", concealment = { "crowd" }, described = 0.5, strikes = 0, known = false,
}) -- awareness per second (0 when it cannot see or there is nothing to see)
-- described: false / true, or 0..1 = how much of a held description the suspect matches
-- known: this observer knows the suspect's face (cfg.known.fillFactor applies, and it notices even an idle one)
local yaw = Perception.sweep(baseYaw, arcDegrees, period, t) -- a camera panning to and fro
Light is 0 (dark) .. 1 (full day). Angles are degrees. Distances are metres.
The interface is documented in the header of init.luau; this file repeats it for the asset browser.