Avoidlight
Based on game build 714014 | Last updated: 2026-03-03
Overview
Avoidlight is a behaviour node used in DST's AI system to make entities avoid illuminated areas. It extends BehaviourNode and interacts with the locomotor component to control directional movement, and with LightWatcher (implicitly) to detect the current light angle. The entity alternates between waiting (stationary) and walking toward a calculated direction opposite to the light source, with added randomness to prevent overly predictable motion.
Usage example
local inst = CreateEntity()
inst:AddComponent("lightwatcher")
inst:AddComponent("locomotor")
inst:AddBehaviourNode("avoidlight")
-- In stategraph or behaviour tree:
inst:DoTaskInTime(0, function() inst.behaviourtree:Start("avoidlight") end)
Dependencies & tags
Components used: locomotor, lightwatcher, physics
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | The entity instance the behaviour operates on. |
waiting | boolean | false | Whether the entity is currently in a waiting (stopped) phase. |
phasechangetime | number | 0 | Timestamp at which the next phase (wait ↔ walk) transition is allowed. |
waittime | number | (unset) | Absolute timestamp used only by the Wait method to schedule sleep. |
angle | number | (unset) | Target direction (in degrees) for walking during a non-waiting phase. |
Main functions
Wait(t)
- Description: Sets a future time for
phasechangetimeand schedules a sleep interval oftseconds within the behaviour tree. Typically used to pause movement briefly before resuming. - Parameters:
t(number) — duration in seconds to wait. - Returns: Nothing.
- Error states: Does not validate
t; expects valid non-negative values.
PickNewAngle()
- Description: Calculates a safe direction away from light by checking adjacent grid tiles for passability and selecting the angle with the largest angular separation from the current light source (or a random angle if no light is detected).
- Parameters: None.
- Returns:
number— A direction angle (in degrees) optimized to avoid light, with ±45° randomness added. - Error states: Returns
0if no grid offsets are passable (e.g., fully surrounded).
Visit()
- Description: Core logic executed each tick of the behaviour node. Alternates between a waiting state (calling
Stopon the locomotor) and a walking state (callingWalkInDirectionwith an angle away from light), using timing and light-level checks to determine transitions. - Parameters: None.
- Returns: Nothing.
- Error states: Does not check whether
self.inst.components.locomotorexists before calling methods — expects the component to be present.
Events & listeners
- Listens to: None identified.
- Pushes: None identified.