NPC Sensing

From Valve Developer Community
Revision as of 01:46, 26 June 2024 by Jiff (talk | contribs)
Jump to navigation Jump to search

Stub

This article or section is a stub. You can help by expanding it.

感知是NPC思考流程的第一阶段。此阶段,NPC将产生可见、可听的实体列表。NPC会忽略它不关心的实体与声响。


Todo: 更多感知(实体与声响)相关的详细说明有助于理解

概念

空间化的NPC感知的两个重要概念是PVS和LOS:

  • PVS Potentially Visible Set/潜在可见集: 一组从NPCvisleaf能够见到的visleafs。PVS是用visleafs测量出的空间区域,对于NPC所在位置而言,它是潜在可视区域。如果另一个实体(通常是Player或者NPC)进入这个区域,那么NPC可能考虑做一个视锥测试及视线测试。与LOS (Line of Sight)相比,PVS不被props和func_detail笔刷限制,也不限于NPC恰好看向的方向。
  • 视锥代表NPC目前的空间几何可见范围: 视锥的有效角度是NPC的FOV角度,视锥长轴线的有效长度是NPC的范围。视锥方向由NPC目前的朝向或其角度决定。 视锥的边界代表了NPC的视野边缘。
  • 范围是NPC能够作出识别或反应时,与目标保持的最远距离。如果FOV是视锥的有效范围,那么范围就是视锥的有效深度。这似乎对所有NPC适用;通常为2048个单位。如果Long Visibility 标记开启, 范围将是无限的, 而Think Outside PVS标记不影响视锥范围。默认情况下,你从NPC的范围外射击NPC时,它什么也不会做。
  • FOV Field of View/视场: 在Source中, NPC的FOV值是 Angular Field of View/角度视场计算的视锥. FOV的边,或者其投影到的一侧代表了视野边缘。(相反,Player的FOV值代表了视锥的水平角FOV,而不是整个视锥。楔体的长方体截面对应着玩家的长方形屏幕)
  • LOS Line of Sight/视线: 如果一个潜在的目标包含在NPC的视锥中,LOS将用射线测试目标是否藏在另一个物体的后面;LOS会被所有的固体几何体阻挡(模型、func_detail笔刷等等),除非笔刷/模型有一个SolidMask固体蒙版NotSolid to LOS/对射线不当作固体,即Transparent/透明。例如(SolidMask:Grate/固体蒙版:架子,对子弹与LOS而言不是固体,还有防弹玻璃等....)
  • 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.