NPC movement: Difference between revisions
Jump to navigation
Jump to search
TomEdwards (talk | contribs) No edit summary |
TomEdwards (talk | contribs) |
||
| Line 92: | Line 92: | ||
Basic movement functions. | Basic movement functions. | ||
;<code>[[ | ;<code>[[SetGoal]](const [[AI_NavGoal_t]] &goal, [[unsigned]] [[int]] flags = 0)</code> | ||
:The standard function for telling an NPC where it should head to when next given the command to move. Can be called with only a vector thanks to an <code>[[AI_NavGoal_t]]</code> overload. | |||
;<code>[[SetDirectGoal]]( [[vector]] &goalPos, [[Navigation_t]] navType = <npc default> )</code> | |||
:Bypasses much of <code>SetGoal</code>'s code. Purpose is unclear. | |||
;<code>[[SetGoalTolerance]]( [[float]] tolerance )</code> | |||
:Allows the NPC to stop a certain distance from the goal, instead of walking directly up to it. Especially useful when the goal is inside an object - e.g. is a collidable model's origin. | |||
;<code>[[SetArrivalDirection]]( [[vector]] || [[QAngle|qangle]] || [[CBaseEntity]] )</code> | |||
:The direction to face on arrival at the task goal. The NPC will probably begin turning shortly before arrival. | :The direction to face on arrival at the task goal. The NPC will probably begin turning shortly before arrival. | ||
:{{tip|If a <code>CBaseEntity</code> is passed the NPC will turn to look at it. To use an entity's angles themselves, call <code>[[GetAbsAngles()]]</code>.}} | :{{tip|If a <code>CBaseEntity</code> is passed the NPC will turn to look at it. To use an entity's angles themselves, call <code>[[GetAbsAngles()]]</code>.}} | ||
;<code>[[StopMoving]]( [[bool]] bImmediate )</code> | |||
:<code>bImmediate</code> doesn't seem to have any effect on walking NPCs - they stop immediately either way. | |||
===[[GetTacticalServices()]]->=== | ===[[GetTacticalServices()]]->=== | ||
Revision as of 13:13, 11 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_LOSGET_FLANK_RADIUS_PATH_TO_ENEMY_LOSGET_FLANK_ARC_PATH_TO_ENEMY_LOSGET_PATH_TO_ENEMY_LKP_LOS- Various hostile-related goal selection tasks.
FIND_COVER_FROM_BEST_SOUNDFIND_HINTNODEFIND_LOCK_HINTNODE
Walk/Run
WALK_PATHRUN_PATHWALK_PATH_FOR_UNITS <units>RUN_PATH_FOR_UNITS <units>WALK_PATH_WITHIN_DIST <units>RUN_PATH_WITHIN_DIST <units>- Basic movement tasks.
WITHIN_DISTare 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.
Bug:Seems to be broken. [todo tested in ?]WEAPON_RUN_PATHITEM_RUN_PATH- Move to pick up a weapon or item; fail if it is picked up or otherwise removed.
SCRIPT_RUN_TO_TARGETSCRIPT_WALK_TO_TARGETSCRIPT_CUSTOM_MOVE_TO_TARGET- For scripted movement.
MOVE_TO_TARGET_RANGEMOVE_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_SOUNDMOVE_AWAY_PATH
Turning/Facing
TURN_RIGHTTURN_LEFTFACE_ENEMYFACE_PLAYERFACE_HINTNODEFACE_LASTPOSITIONFACE_SAVEPOSITIONFACE_AWAY_FROM_SAVEPOSITIONFACE_TARGETFACE_IDEALFACE_SCRIPTFACE_PATHFACE_REASONABLE
SavePosition
STORE_POSITION_IN_SAVEPOSITIONSTORE_BESTSOUND_IN_SAVEPOSITIONCLEAR_LASTPOSITIONSTORE_LASTPOSITIONTASK_STORE_BESTSOUND_REACTORIGIN_IN_SAVEPOSITIONTASK_STORE_ENEMY_POSITION_IN_SAVEPOSITIONTASK_FIND_BACKAWAY_FROM_SAVEPOSITION
Utility
WAIT_FOR_MOVEMENT <float|seconds>- Wait this long for any ongoing movement to complete (pass
0to 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: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
Basic movement functions.
SetGoal(const AI_NavGoal_t &goal, unsigned int flags = 0)- The standard function for telling an NPC where it should head to when next given the command to move. Can be called with only a vector thanks to an
AI_NavGoal_toverload. SetDirectGoal( vector &goalPos, Navigation_t navType = <npc default> )- Bypasses much of
SetGoal's code. Purpose is unclear. SetGoalTolerance( float tolerance )- Allows the NPC to stop a certain distance from the goal, instead of walking directly up to it. Especially useful when the goal is inside an object - e.g. is a collidable model's origin.
SetArrivalDirection( vector || qangle || CBaseEntity )- The direction to face on arrival at the task goal. The NPC will probably begin turning shortly before arrival.
Tip:If a CBaseEntityis passed the NPC will turn to look at it. To use an entity's angles themselves, callGetAbsAngles().StopMoving( bool bImmediate )bImmediatedoesn't seem to have any effect on walking NPCs - they stop immediately either way.
GetTacticalServices()->
Combat movement functions.