NPC movement: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(more tasks)
Line 3: Line 3:
== Schedule tasks ==
== Schedule tasks ==


All of these tasks can be found in <code>[[CAI_BaseNPC]]::[[StartTask()]]</code>.
All of these tasks can be found in <code>[[CAI_BaseNPC]]::[[StartTask()]]</code>. ''Their <code>TASK_</code> prefixes have been removed for readability.''


=== Find targets ===
=== Find targets ===


;<code>TASK_GET_PATH_TO_PLAYER</code>
;<code>GET_PATH_TO_PLAYER</code>
:Sets the NPC's goal to the player's location at the time of calculation.
:Sets the NPC's goal to the player's location at the time of calculation.
;<code>WANDER <int|min_dist * 10000 + int|max_dist></code>
:Pick a random location for a goal. The parameter is complex because it is actually two values forced into one.


=== Walk/Run path ===
=== Walk/Run path ===


;<code>TASK_WALK_PATH</code>
;<code>WALK_PATH</code>
;<code>TASK_RUN_PATH</code>
;<code>RUN_PATH</code>
;<code>TASK_WALK_PATH_FOR_UNITS <[[unit]]s></code>
;<code>WALK_PATH_FOR_UNITS <[[unit]]s></code>
;<code>TASK_RUN_PATH_FOR_UNITS <[[unit]]s></code>
;<code>RUN_PATH_FOR_UNITS <[[unit]]s></code>
;<code>TASK_WALK_PATH_WITHIN_DIST <[[unit]]s></code>
;<code>WALK_PATH_WITHIN_DIST <[[unit]]s></code>
;<code>TASK_RUN_PATH_WITHIN_DIST <[[unit]]s></code>
;<code>RUN_PATH_WITHIN_DIST <[[unit]]s></code>
:Basic movement tasks. <code>WITHIN_DIST</code> are useful when the target itself isn't accessible, e.g. is an entity's origin.
:Basic movement tasks. <code>WITHIN_DIST</code> are useful when the target itself isn't accessible, e.g. is an entity's origin.
;<code>TASK_RUN_PATH_FLEE <[[unit]]s></code>
;<code>RUN_PATH_FLEE <[[unit]]s></code>
:Run this many units. Won't set a goal though, so use it in conjunction with another task.
:Run this many units. Won't set a goal though, so use it in conjunction with another task.
;<code>TASK_WALK_PATH_TIMED <float|seconds></code>
;<code>WALK_PATH_TIMED <float|seconds></code>
;<code>TASK_RUN_PATH_TIMED <float|seconds></code>
;<code>RUN_PATH_TIMED <float|seconds></code>
:Wait this many seconds, ''then'' move. Seems broken?
:Wait this many seconds, ''then'' move.
:{{bug|Seems to be broken. Use <code>WAIT_FOR_MOVEMENT <float></code> (see next subheading) instead.}}
;<code>WEAPON_RUN_PATH</code>
;<code>ITEM_RUN_PATH</code>
:Move to pick up a weapon or item; fail if it is picked up or otherwise removed.
;<code>TASK_SCRIPT_RUN_TO_TARGET</code>
;<code>TASK_SCRIPT_WALK_TO_TARGET</code>
;<code>TASK_SCRIPT_CUSTOM_MOVE_TO_TARGET</code>
:For scripted movement.


=== Utility ===
=== Utility ===


;<code>TASK_WAIT_FOR_MOVEMENT</code>
;<code>WAIT_FOR_MOVEMENT <float|seconds></code>
:Has the NPC wait for any previously-initiated movement to complete before starting the next task or changing schedule. Only your specified interrupts will stop it from moving. '''''Very important!'''''
:Wait this long for any ongoing movement to complete (pass <code>0</code> to wait forever if necessary). A very common task.
;<code>TASK_SET_ROUTE_SEARCH_TIME <seconds></code>
;<code>WAIT_FOR_MOVEMENT_STEP <float|seconds></code>
:Same as above, but fails if the goal is a cover location which a hostile has [[Line of sight|LOS]] to.
;<code>SET_ROUTE_SEARCH_TIME <seconds></code>
:Maximum time to spend building a route. The schedule will fail if it is overrun. Remember that different CPU speeds will give different results - don't use it except as a fail-safe.
:Maximum time to spend building a route. The schedule will fail if it is overrun. Remember that different CPU speeds will give different results - don't use it except as a fail-safe.



Revision as of 11:15, 7 April 2008

This is a list of important components of an NPC movement schedule and task. One day it may end up as a full tutorial.

Schedule tasks

All of these tasks can be found in CAI_BaseNPC::StartTask(). Their TASK_ prefixes have been removed for readability.

Find targets

GET_PATH_TO_PLAYER
Sets the NPC's goal to the player's location at the time of calculation.
WANDER <int|min_dist * 10000 + int|max_dist>
Pick a random location for a goal. The parameter is complex because it is actually two values forced into one.

Walk/Run path

WALK_PATH
RUN_PATH
WALK_PATH_FOR_UNITS <units>
RUN_PATH_FOR_UNITS <units>
WALK_PATH_WITHIN_DIST <units>
RUN_PATH_WITHIN_DIST <units>
Basic movement tasks. WITHIN_DIST are useful when the target itself isn't accessible, e.g. is an entity's origin.
RUN_PATH_FLEE <units>
Run this many units. Won't set a goal though, so use it in conjunction with another task.
WALK_PATH_TIMED <float|seconds>
RUN_PATH_TIMED <float|seconds>
Wait this many seconds, then move.
Icon-Bug.pngBug:Seems to be broken. Use WAIT_FOR_MOVEMENT <float> (see next subheading) instead.  [todo tested in ?]
WEAPON_RUN_PATH
ITEM_RUN_PATH
Move to pick up a weapon or item; fail if it is picked up or otherwise removed.
TASK_SCRIPT_RUN_TO_TARGET
TASK_SCRIPT_WALK_TO_TARGET
TASK_SCRIPT_CUSTOM_MOVE_TO_TARGET
For scripted movement.

Utility

WAIT_FOR_MOVEMENT <float|seconds>
Wait this long for any ongoing movement to complete (pass 0 to wait forever if necessary). A very common task.
WAIT_FOR_MOVEMENT_STEP <float|seconds>
Same as above, but fails if the goal is a cover location which a hostile has LOS to.
SET_ROUTE_SEARCH_TIME <seconds>
Maximum time to spend building a route. The schedule will fail if it is overrun. Remember that different CPU speeds will give different results - don't use it except as a fail-safe.

Task functions

GetNavigator()->

Basic movement functions.

SetArrivalDirection( vector || qangle || CBaseEntity )
The direction to face on arrival at the task goal. The NPC will probably begin turning shortly before arrival.
Tip.pngTip:If a CBaseEntity is passed the NPC will turn to look at it. To use an entity's angles themselves, call GetAbsAngles().

GetTacticalServices()->

Combat movement functions.