Talk:NPC Sensing

From Valve Developer Community
Jump to: navigation, search


So far I've figured out that two of the key concepts for spatialised NPC senses are PVS and LOS:

  • PVS Potentially Visible Set - the group of visleafs which are visible from the NPC's visleaf. PVS is the spatial area (measured in visleafs) that is potentially visible to the NPC from his current location (ie the visleaf he is in). If another entity (usually a Player or NPC) enters this area the NPC will do a Viewcone test and/or an LOS test?. NPCs may also "Think outside PVS" by using the NPC memory feature(?). In contrast to the NPC's LOS (Line of Sight), PVS is not restricted by props and func_detail brushes, or the direction in which the NPC happens to be looking.
  • Viewcone represents the spatial geometry of the NPC's current Visual Field - the angle or scope of the cone is the NPC's FOV angle and the length or depth of the cone's long axis is the NPC's Range. The Viewcone direction is determined by the NPCs current orientation, or Angles. The edges or boundries of the Viewcone represent the NPC's Periphery of Vision.
  • Range is the maximum distance between the target and the NPC where the NPC will recognise/react to the target's presence. If FOV is the "Scope" of the Viewcone, Range is the "Depth" of the Viewcone. It appears to be the same for all NPCs; 2048 units. If the Long Visibility flag is set, range seems to be unlimited. The Think Outside PVS flag does not effect viewcone range. By default if you shoot an NPC from outside its range it does nothing about it.
  • FOV Field of View - In Source, an NPC's FOV value is the Angular Field of View used to calculate its Viewcone. The edge of the FOV, or projected sides of the viewcone represent the periphery of vision. (By contrast, the Player's FOV value represents the Horizontal Angular Field of View of a Viewwedge rather than a viewcone. The wedge's rectangular cross-section corresponds to the Player's rectangular screen.)
  • LOS Line of Sight - If a potential target is within the NPC's Viewcone, the LOS 'ray trace' test checks if the target is hidden from view by another object; LOS is blocked by all Solid geometry (Models, func_detail brushes, etc.) unless the brush/model is has a SolidMask that is NotSolid to LOS, ie Transparent. (eg SolidMask:Grate is NotSolid to bullets & LOS, whereas Unbreakable Glass ...?)
  • PAS Potentially Audible Set is the spatial area (measured in visleafs) in which sound sources are potentially audible to the NPC. Unlike Vision, Hearing is not limited to a directional Viewcone. (PAS - discovered in BSP compile log)

--Beeswax 08:35, 5 Apr 2008 (PDT)

NPC Configuration

However I'm still struggling to understand what almost all of these BaseNPC entity 'object property' settings actually mean / do. So far my attempts at empirical testing of AI behaviours have been entirely inconclusive!

BaseNPC properties stimulated by PVS?

  • BaseNPC Flag : 1024 : "Think outside PVS" : 0
"Thinking outside the PVS" means that it tests all entities in the map (or possibly a given radius) --TomEdwards
"Think outside PVS" does not override or extend viewcone sensing.
  • BaseNPC Output : "OnHearWorld" "" : Fired when this NPC hears a sound (other than combat or the player).
  • BaseNPC Output : "OnHearPlayer" "" : Fired when this NPC hears the player.
  • BaseNPC Output : "OnHearCombat" "" : Fired when this NPC hears combat sounds.
if when this NPC hears means within earshot = within PVS ? or calculated from (loudness/distance)/NPC_deafness ?
what exactly are player sounds, combat sounds and especially a sound (other than combat or the player) ?
  • ai_sound : This entity makes abstract sounds or smells that can be sensed by NPCs, but not by the player. This can be used to cause reactions in nearby NPCs.
does this come in here or is it part of the Response System?


Sleep State Holds the NPC in stasis until specified condition. See also 'Wake Radius' and 'Wake Squad'.

this would seem to be a list of triggers for an undocumented NPC_State ?
It prevents the NPC from being rendered or thinking. Instead it waits for the correct conditions to become active. It's not really an AI state at all. --TomEdwards 02:52, 7 Mar 2008 (PST)
  • BaseNPC Keyvalue : "sleepstate" "0" : None (default).
what is normal behaviour if not "Waiting for PVS" stimulus?
  • BaseNPC Keyvalue : "sleepstate" "1" : Waiting for threat.
what exactly is a threat ? enemy or grenade within PVS ?
  • BaseNPC Keyvalue : "sleepstate" "2" : Waiting for PVS.
  • BaseNPC Keyvalue : "sleepstate" "3" : Waiting for input, ignore PVS.
similar to "Wait For Script" flag I guess ?
  • BaseNPC Keyvalue : "sleepstate" "4" : Auto PVS.
what on earth is Auto PVS ?
  • BaseNPC Keyvalue : "sleepstate" "5" : Auto PVS after PVS.
what ... ?
  • BaseNPC Keyvalue :"wakeradius" "<float>" : Auto-wake if player within this distance.
I assume this would override the sleepstate/PVS then, ignoring PVS stimuli?
  • BaseNPC pseudo Input via : "wakesquad" from another NPC if this NPC is assigned to the same "squadname".
SleepState generic I/Os
  • BaseNPC Input : "Wake" "" : Wakes up the NPC if it is sleeping.
  • 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 properties stimulated by LOS (within Viewcone)

  • BaseNPC Flag : 1 : "Wait Till Seen" : 0
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.
  • BaseNPC Flag : 256 : "Long Visibility/Shoot" : 0
Usually, the Range at which an NPC is activated by an enemy within its Viewcone is about 2048 units (this does not vary between NPC classes). With this flag set, the NPC's ViewCone range seems to be unlimited. Beeswax
  • BaseNPC Output : "OnFoundEnemy" & "OnFoundPlayer" : Fired when this NPC establishes line of sight to its Enemy/Player. Sends "<enemyname>" as a parameter.
  • BaseNPC Output : "OnLostEnemyLOS" & "OnLostPlayerLOS" : Fired when this NPC loses line of sight to its Enemy/Player.
  • BaseNPC Output : "OnLostEnemy" & "OnLostPlayer" : Fired when this NPC loses its Enemy/Player. Usually due to the enemy being killed/removed, or because this NPC has selected a newer, more dangerous enemy.
killed I understand, removed I guess refers to targetname inputs (Kill & KillHierarchy), but how does an NPC decide to select a new, more dangerous enemy?
NPCs pursue Targets, making it difficult for the player to simply move out of the NPC's PVS.

My three cents

I fleshed out most of the side articles, but you seem to know more than me, so I'm leaving the NPC_Sensing article to someone who really knows stuff.

As for OnLostEnemy/OnLostPlayer, the NPC hasn't lost its target just because it has lost line of sight to it. It will carry on chasing after/searching for a hidden target for awhile - usually for about 30 seconds or so. After that OnLostEnemy/OnLostPlayer can trigger it to return to its post, so that it doesn't just stand around like the zombies in Flesh do (although that was creepy as well). In my stealth mod, I loop the heartbeat sound between zombies finding me and them losing me, to determine if it's wise to hide or not. --MossyBucket (formerly Andreasen) 22:50, 1 February 2011 (UTC)

Found this orphaned article, about IMPROVING how an NPC handles PAS: AI Perception Behavior Enhancement --MossyBucket (formerly Andreasen) 20:43, 2 February 2011 (UTC)