NPC Sensing
感知是NPC思考流程的第一阶段。此阶段,NPC将产生可见、可听的实体列表。NPC会忽略它不关心的实体与声响。
概念
空间化的NPC感知的两个重要概念是PVS和LOS:
- PVS Potentially Visible Set/潜在可见集: 一组从NPCvisleaf能够见到的visleafs。PVS是用visleafs测量出的空间区域,对于NPC所在位置而言,它是潜在可视区域。如果另一个实体(通常是Player或者NPC)进入这个区域,那么NPC可能考虑做一个视锥测试及视线测试。与LOS (Line of Sight)相比,PVS不被props和func_detail笔刷限制,也不限于NPC恰好看向的方向。
- FOV Field of View/视场: 在Source中, NPC的FOV值是 Angular Field of View/角度视场计算的视锥. FOV的边,或者其投影到的一侧代表了视野边缘。(相反,Player的FOV值代表了视锥的水平角FOV,而不是整个视锥。楔体的长方体截面对应着玩家的长方形屏幕)
- PAS Potentially Audible Set/潜在声音集: PVS是用visleafs测量出的空间区域,在这个区域内的声源NPC可能听得到。与视野不同,听觉不受限于有方向的视锥。
NPC Configuration
A quick overview of NPC entity configuration within Hammer to accomplish various NPC behaviour.
KeyValues
Squad Name
NPCs that are in the same squad (i.e. have matching squad names) will share information about enemies, and (depending on AI capabilities) will take turns attacking and covering each other.
Sleep State
Sleep State Holds the NPC in stasis until specified condition.
Sleeping prevents the NPC from being rendered or thinking. Instead it waits for a Wake input or for the specified condition to become active. Sleeping NPCs do not play idle sounds either. It is common to have NPCs in 'inactive' portions of the map sleep, for performance reasons.
- sleepstate = 0 : None (default)
- NPC does not sleep when spawned.
- sleepstate = 1 : Waiting for threat
- NPC sleeps initially. Wakes the NPC once it establishes LOS with a threat.
- The LOS test is independent of NPC Viewcone. If a line can be drawn between the NPC and the threat, the NPC is woken up.
- This setting can make the NPC pop into view e.g. when turning around a corner.
- [Clarify]: What exactly constitutes a threat, besides enemies?
- sleepstate = 2 : Waiting for PVS
- NPC sleeps initially. Wakes the NPC once the player enters the NPC's PVS.
- This can be very early depending on the world geometry. But it should ensure that the NPC does not suddenly pop into view.
- sleepstate = 3 : Waiting for input, ignore PVS
- NPC sleeps initially. Can only be woken through external inputs, such as the Wake input, or by squad mates (if they have Wake Squad set), or through the Wake Radius (see below).
- sleepstate = 4 : Auto PVS
- NPC sleeps initially. Wakes the NPC once the player enters the NPC's PVS. Puts it to sleep again, once outside PVS. This will even pause enemies pursuing the player. They won't forget their target, though, and continue pursuing once woken up again.
- Should not be used with Wake Radius, it can create an infinite wake-sleep loop when the player is inside the wake radius, but not inside its PVS.
- sleepstate = 5 : Auto PVS after PVS
- NPC doesn't sleep initially. After establishing 'PVS contact' once, it goes to Auto PVS mode.
Wake Radius
Auto-wake if player within this distance.
If non-zero, this wakes the NPC as soon as the player is within this distance. Waking by distance complements the Sleep State waking conditions, it does not override them.
Wake Squad
If set to "Yes", the NPC automatically wakes all squad mates when waking up.
Flags
- Wait for Script
- Not the same as sleeping.
- The NPC's Sensing only becomes active after playing a script such as scripted_sequence or aiscripted_schedule. That means it will initially not acquire enemies. This can be used to keep the NPC in place before triggering the script. After the script has been completed, the NPC leaves the waiting state. The same happens when the NPC is being attacked.
- Wait Till Seen
- The NPC's Sensing only becomes active after the Player has seen the NPC. The "seen by player" test does not seem to use the Player's entire FOV.
I/O for NPC scripting
- BaseNPC Input : "Wake" : Wakes up the NPC if it is sleeping.
- BaseNPC Input : "UpdateEnemyMemory" (targetname) : Updates the NPC's memory of the specified target. Useful for making NPCs aware of an enemy, such as !player.
- BaseNPC Output : "OnSleep" : Fired when this NPC enters a sleep state.
- BaseNPC Output : "OnWake" : Fired when this NPC comes out of a sleep state.
- BaseNPC Outputs : "OnFoundPlayer" / "OnFoundEnemy" (targetname) : Fired when the NPC finds the player / an enemy. NPC must not be sleeping or scripting for this to work.