Decision Making Overview: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (categorized)
m (Reverted edits by Jiff (talk) to last revision by Beeswax)
Tag: Rollback
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
From a high-level perspective, [[NPC]]s follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.
From a high-level perspective, [[NPC]]s follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.


Each time an NPC "thinks", it does the following:
Each time an NPC [[Think()|thinks]], it follows this routine:
*'''Perform Sensing'''
 
**The NPC generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities & sounds that it doesn't care about, and hence doesn't place them into the lists.
;Perform Sensing
*'''Generate a list of [[Conditions]]'''
:[[NPC Sensing]] generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities and sounds that it doesn't care about.
**[[Conditions]] are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Examples of conditions are: ''"I can see an enemy"'', ''"I have taken some damage"'', or ''"My weapon's clip is empty"''.
;Generate a list of Conditions
*'''Choose an appropriate [[State]]'''
:[[Conditions]] are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Conditions might include:
**The [[State|NPC State]] is the overall assessment of the NPC based upon the list of [[Conditions]]. For example: NPCs with a visible enemy will consider themselves in ''Combat State''. NPCs who have no enemies left after killing one will drop back to ''Alert State''. NPCs with a health of 0 would move to ''Dead State''.
:*I can see an enemy
*'''Select a new [[Schedule]] if appropriate'''
:*I have taken some damage
**The [[Schedule|Schedule]] is the overall action being taken by the NPC, which is then broken down into sub parts for the NPC to actually perform. Schedules are chosen based upon the NPCs current [[State]], and the list of [[Conditions]]. Examples of schedules are: ''"I'm taking cover to reload my gun"'', ''"I'm chasing after my enemy"'', ''"I'm moving to a position where I have line-of-sight to my enemy"''.
:*My weapon's clip is empty
**NPCs will choose a new schedule for one of two reasons:
;Choose an appropriate State
***They finish performing the last part of the current schedule.
:The [[State]] is the overall assessment of the NPC based upon the<!-- global?--> list of Conditions. For example:
***They generate a condition that their current schedule has specified as an [[Interrupt]].
:*NPCs with a visible enemy enter ''Combat''
**If neither of these are true, the NPC will continue running its current schedule.
:*NPCs who have no enemies left will drop back to ''Alert''
*'''Perform the current [[Task]]'''
:*NPCs with a health of 0 would move to ''Dead''
**The [[Task]] is the sub part of a [[Schedule]] that describes a discrete action within the schedule. The tasks must be performed, one by one, for the schedule to be completed. For example, the ''"I'm taking cover to reload my gun"'' schedule would be broken down into the following tasks: ''"Find a position to take cover at"'', ''"Generate a path to that position"'', ''"Run the path"'', and then ''"Reload my gun"''.
;Select a new Schedule if appropriate  
**Many tasks take some time to perform (like the ''"Run the path"'' task in the above example), so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left.
:The [[Schedule]] is the overall action being taken by the NPC, which is then broken down into Tasks (see below) for the NPC to actually perform. Schedules are chosen based upon the NPC's current State and Conditions. Examples might include:
:*I'm taking cover to reload my gun
:*I'm chasing after my enemy
:*I'm moving to a position where I have line-of-sight to my enemy
:NPCs will choose a new schedule for one of two reasons:
:#They finish performing their last schedule
:#They generate a condition that their current schedule has specified as an [[Interrupt]]
;Perform the current Task
:The [[Task]] is a component of a Schedule that describes a discrete action. Tasks must be performed one by one for the schedule to be completed. For example, the "I'm taking cover to reload my gun" schedule would be broken down into the following tasks:
:#Find a position to take cover at
:#Generate a path to that position
:#Run the path
:#Reload my gun
:Many tasks, like the one above, take time to perform, so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left. If a task fails, the schedule fails. <!-- is this always true? -->


[[Category: AI]]
[[Category: AI]]

Latest revision as of 01:59, 26 June 2024

From a high-level perspective, NPCs follow a fairly simple (and real-world logical) process for making decisions. The easiest way to understand it is to examine the basic outline first, and then dig further into the necessary exceptions afterwards.

Each time an NPC thinks, it follows this routine:

Perform Sensing
NPC Sensing generates a list of entities that it can see, and another list of NPC sounds that it can hear. The NPC ignores entities and sounds that it doesn't care about.
Generate a list of Conditions
Conditions are key pieces of information that the NPC will be using to make a decision. They are extracted from the sensed lists of entities & sounds, and from the state of the world and the NPC. Conditions might include:
  • I can see an enemy
  • I have taken some damage
  • My weapon's clip is empty
Choose an appropriate State
The State is the overall assessment of the NPC based upon the list of Conditions. For example:
  • NPCs with a visible enemy enter Combat
  • NPCs who have no enemies left will drop back to Alert
  • NPCs with a health of 0 would move to Dead
Select a new Schedule if appropriate
The Schedule is the overall action being taken by the NPC, which is then broken down into Tasks (see below) for the NPC to actually perform. Schedules are chosen based upon the NPC's current State and Conditions. Examples might include:
  • I'm taking cover to reload my gun
  • I'm chasing after my enemy
  • I'm moving to a position where I have line-of-sight to my enemy
NPCs will choose a new schedule for one of two reasons:
  1. They finish performing their last schedule
  2. They generate a condition that their current schedule has specified as an Interrupt
Perform the current Task
The Task is a component of a Schedule that describes a discrete action. Tasks must be performed one by one for the schedule to be completed. For example, the "I'm taking cover to reload my gun" schedule would be broken down into the following tasks:
  1. Find a position to take cover at
  2. Generate a path to that position
  3. Run the path
  4. Reload my gun
Many tasks, like the one above, take time to perform, so the NPC will keep performing that task each time it thinks until the task is completed. Then, it'll move onto then next task in the current schedule, or pick a new schedule if there are no tasks left. If a task fails, the schedule fails.