Zh/NPC Sensing: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
(Created page with "{{langsp|title=感知}} '''感知'''是NPC思考流程的第一阶段。此阶段,NPC将产生可见、可听的实体列表。NPC会忽略它不关心的实体与声响。...")
 
No edit summary
Line 17: Line 17:
*[[PAS]] '''Potentially Audible Set/潜在声音集''': PVS是用visleafs测量出的空间区域,在这个区域内的声源NPC可能听得到。与视野不同,听觉不受限于有方向的视锥。
*[[PAS]] '''Potentially Audible Set/潜在声音集''': PVS是用visleafs测量出的空间区域,在这个区域内的声源NPC可能听得到。与视野不同,听觉不受限于有方向的视锥。


==NPC Configuration==
==NPC 配置==
A quick overview of NPC entity configuration within Hammer to accomplish various NPC behaviour.
快速概括NPC实体在Hammer中实现各种NPC行为的配置。


=== KeyValues ===
=== 键值 ===


==== Squad Name ====
==== 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.
NPCs有相同的小队名(以及相匹配的小队名)会共享敌人信息,并且会采取轮番攻击以及掩护彼此(取决于AI能力)。


==== Sleep State ====
==== Sleep State睡眠状态 ====
''Sleep State Holds the NPC in stasis until specified condition.''
''睡眠状态将让npc停滞直到指定的条件达成''


Sleeping prevents the NPC from being rendered or thinking. Instead it waits for a ''Wake'' input or for the specified condition to become active.
睡眠状态将阻止NPC渲染与思考(think) ,并且它会等待''Wake''输入或特定条件的达成。
Sleeping NPCs do not play idle sounds either. It is common to have NPCs in 'inactive' portions of the map sleep, for performance reasons.
睡眠的NPC也不会播放无用的声响。出于性能原因,让NPC作为地图未激活的一部分进入睡眠状态很寻常。


* '''sleepstate = 0 : None (default)'''
* '''sleepstate = 0 : None (default)'''
: NPC does not sleep when spawned.
: NPC生成时不会进入睡眠状态。


* '''sleepstate = 1 : Waiting for threat'''
* '''sleepstate = 1 : Waiting for threat'''
: NPC sleeps initially. Wakes the NPC once it establishes [[LOS]] with a threat.
: NPC初始即睡眠状态。一旦建立威胁[[LOS]],NPC将被唤醒。
: 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.
: LOS测试是独立于NPC[[Viewcone]]的。只要NPC与威胁之间可以画出一条线,那么NPC将被唤醒。
: This setting can make the NPC pop into view e.g. when turning around a corner.
: 这个设置可以让NPC纳入视野。例如在转角的情况。
: {{clarify}}: What exactly constitutes a ''threat'', besides enemies?
: {{clarify}}: 除了敌人之外什么构成''威胁''


* '''sleepstate = 2 : Waiting for PVS'''
* '''sleepstate = 2 : Waiting for PVS'''
: NPC sleeps initially. Wakes the NPC once the player enters the NPC's [[PVS]].
: NPC初始即睡眠状态。一旦玩家进入NPC的[[PVS]],NPC将被唤醒。
: This can be very early depending on the world geometry. But it should ensure that the NPC does not suddenly pop into view.
: 根据世界几何体的情况, NPC可以被很早的唤醒。但应该确保NPC不会突然出现在视野内。


* '''sleepstate = 3 : Waiting for input, ignore PVS'''
* '''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).
: NPC初始即睡眠状态。NPC仅可以被外部输入唤醒,例如wake输入,小队成员(须有''唤醒小队''集),唤醒半径(见下方)。


* '''sleepstate = 4 : Auto PVS'''
* '''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.
: NPC初始即睡眠状态。一旦玩家进入NPC的PVS,NPC将被唤醒。只要离开PVS后,NPC又将进入睡眠状态,这甚至能暂停敌人对玩家的追逐。然而,它们不会忘记自己的目标,一旦被唤醒将继续追逐。
: 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.
: 不应该与''Wake Radius''一同使用。当玩家在唤醒半径,但是又不在PVS时,这可能制造唤醒-睡眠的无限循环。


* '''sleepstate = 5 : Auto PVS after PVS'''
* '''sleepstate = 5 : Auto PVS after PVS'''
: NPC doesn't sleep initially. After establishing 'PVS contact' once, it goes to ''Auto PVS'' mode.
: NPC初始即睡眠状态。在首次建立'PVS接触'时,它将进入自动PVS模式。


==== Wake Radius ====
==== Wake Radius ====

Revision as of 06:06, 26 June 2024

English (en)中文 (zh)Translate (Translate)

感知是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恰好看向的方向。
  • 视锥代表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 配置

快速概括NPC实体在Hammer中实现各种NPC行为的配置。

键值

Squad Name小队名

NPCs有相同的小队名(以及相匹配的小队名)会共享敌人信息,并且会采取轮番攻击以及掩护彼此(取决于AI能力)。

Sleep State睡眠状态

睡眠状态将让npc停滞直到指定的条件达成

睡眠状态将阻止NPC渲染与思考(think) ,并且它会等待Wake输入或特定条件的达成。 睡眠的NPC也不会播放无用的声响。出于性能原因,让NPC作为地图未激活的一部分进入睡眠状态很寻常。

  • sleepstate = 0 : None (default)
NPC生成时不会进入睡眠状态。
  • sleepstate = 1 : Waiting for threat
NPC初始即睡眠状态。一旦建立威胁LOS,NPC将被唤醒。
LOS测试是独立于NPCViewcone的。只要NPC与威胁之间可以画出一条线,那么NPC将被唤醒。
这个设置可以让NPC纳入视野。例如在转角的情况。
[澄清]: 除了敌人之外什么构成威胁
  • sleepstate = 2 : Waiting for PVS
NPC初始即睡眠状态。一旦玩家进入NPC的PVS,NPC将被唤醒。
根据世界几何体的情况, NPC可以被很早的唤醒。但应该确保NPC不会突然出现在视野内。
  • sleepstate = 3 : Waiting for input, ignore PVS
NPC初始即睡眠状态。NPC仅可以被外部输入唤醒,例如wake输入,小队成员(须有唤醒小队集),唤醒半径(见下方)。
  • sleepstate = 4 : Auto PVS
NPC初始即睡眠状态。一旦玩家进入NPC的PVS,NPC将被唤醒。只要离开PVS后,NPC又将进入睡眠状态,这甚至能暂停敌人对玩家的追逐。然而,它们不会忘记自己的目标,一旦被唤醒将继续追逐。
不应该与Wake Radius一同使用。当玩家在唤醒半径,但是又不在PVS时,这可能制造唤醒-睡眠的无限循环。
  • sleepstate = 5 : Auto PVS after PVS
NPC初始即睡眠状态。在首次建立'PVS接触'时,它将进入自动PVS模式。

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.