NPC movement: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
;<code>WANDER <int|min_dist * 10000 + int|max_dist></code>
;<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.
:Pick a random location for a goal. The parameter is complex because it is actually two values forced into one.
;<code>GET_PATH_TO_ENEMY_LOS</code>
;<code>GET_FLANK_RADIUS_PATH_TO_ENEMY_LOS</code>
;<code>GET_FLANK_ARC_PATH_TO_ENEMY_LOS</code>
;<code>GET_PATH_TO_ENEMY_LKP_LOS</code>
:Various hostile-related goal selection tasks.
;<code>FIND_COVER_FROM_BEST_SOUND</code>
;<code>FIND_HINTNODE</code>
;<code>FIND_LOCK_HINTNODE</code>


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


;<code>WALK_PATH</code>
;<code>WALK_PATH</code>
Line 26: Line 34:
;<code>RUN_PATH_TIMED <float|seconds></code>
;<code>RUN_PATH_TIMED <float|seconds></code>
:Wait this many seconds, ''then'' move.
:Wait this many seconds, ''then'' move.
:{{bug|Seems to be broken. Use <code>WAIT_FOR_MOVEMENT <float></code> (see next subheading) instead.}}
:{{bug|Seems to be broken.}}
;<code>WEAPON_RUN_PATH</code>
;<code>WEAPON_RUN_PATH</code>
;<code>ITEM_RUN_PATH</code>
;<code>ITEM_RUN_PATH</code>
Line 34: Line 42:
;<code>SCRIPT_CUSTOM_MOVE_TO_TARGET</code>
;<code>SCRIPT_CUSTOM_MOVE_TO_TARGET</code>
:For scripted movement.
:For scripted movement.
;<code>MOVE_TO_TARGET_RANGE</code>
;<code>MOVE_TO_GOAL_RANGE</code>
:Move within weapons range. Identical, except that one uses a goal while the other uses a target entity.
;<code>GET_PATH_AWAY_FROM_BEST_SOUND</code>
;<code>MOVE_AWAY_PATH</code>
=== Turning/Facing ===
;<code>TURN_RIGHT</code>
;<code>TURN_LEFT</code>
;<code>FACE_ENEMY</code>
;<code>FACE_PLAYER</code>
;<code>FACE_HINTNODE</code>
;<code>FACE_LASTPOSITION</code>
;<code>FACE_SAVEPOSITION</code>
;<code>FACE_AWAY_FROM_SAVEPOSITION</code>
;<code>FACE_TARGET</code>
;<code>FACE_IDEAL</code>
;<code>FACE_SCRIPT</code>
;<code>FACE_PATH</code>
;<code>FACE_REASONABLE</code>
=== SavePosition ===
;<code>STORE_POSITION_IN_SAVEPOSITION</code>
;<code>STORE_BESTSOUND_IN_SAVEPOSITION</code>
;<code>CLEAR_LASTPOSITION</code>
;<code>STORE_LASTPOSITION</code>
;<code>TASK_STORE_BESTSOUND_REACTORIGIN_IN_SAVEPOSITION</code>
;<code>TASK_STORE_ENEMY_POSITION_IN_SAVEPOSITION</code>
;<code>TASK_FIND_BACKAWAY_FROM_SAVEPOSITION</code>


=== Utility ===
=== Utility ===
Line 44: Line 83:
;<code>SET_ROUTE_SEARCH_TIME <seconds></code>
;<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.
;<code>STOP_MOVING</code>
:Like, ''duh.''


== Task functions ==
== Task functions ==

Revision as of 11:38, 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.
GET_PATH_TO_ENEMY_LOS
GET_FLANK_RADIUS_PATH_TO_ENEMY_LOS
GET_FLANK_ARC_PATH_TO_ENEMY_LOS
GET_PATH_TO_ENEMY_LKP_LOS
Various hostile-related goal selection tasks.
FIND_COVER_FROM_BEST_SOUND
FIND_HINTNODE
FIND_LOCK_HINTNODE

Walk/Run

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.  [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.
SCRIPT_RUN_TO_TARGET
SCRIPT_WALK_TO_TARGET
SCRIPT_CUSTOM_MOVE_TO_TARGET
For scripted movement.
MOVE_TO_TARGET_RANGE
MOVE_TO_GOAL_RANGE
Move within weapons range. Identical, except that one uses a goal while the other uses a target entity.
GET_PATH_AWAY_FROM_BEST_SOUND
MOVE_AWAY_PATH

Turning/Facing

TURN_RIGHT
TURN_LEFT
FACE_ENEMY
FACE_PLAYER
FACE_HINTNODE
FACE_LASTPOSITION
FACE_SAVEPOSITION
FACE_AWAY_FROM_SAVEPOSITION
FACE_TARGET
FACE_IDEAL
FACE_SCRIPT
FACE_PATH
FACE_REASONABLE

SavePosition

STORE_POSITION_IN_SAVEPOSITION
STORE_BESTSOUND_IN_SAVEPOSITION
CLEAR_LASTPOSITION
STORE_LASTPOSITION
TASK_STORE_BESTSOUND_REACTORIGIN_IN_SAVEPOSITION
TASK_STORE_ENEMY_POSITION_IN_SAVEPOSITION
TASK_FIND_BACKAWAY_FROM_SAVEPOSITION

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.
Tip.pngTip:Given the name, Valve presumably intended this task to handle all sorts of "mid-stride" fails that didn't make good interrupts. This makes it a good place to add your own!
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.
STOP_MOVING
Like, duh.

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.