Skip to content

KAI_MoveAway()

inkoalawetrust edited this page Aug 11, 2024 · 5 revisions

KAI_MoveAway (Actor Other[, Int Attempts = 32, Double RunRad = 128, Int MaxSteps = 32, Double DetourFactor = 1.0, Double AngleLimit = 10, Int ChaseFlags = 0, Int Flags = 0, Int KMAFlags = 0, Vector3 TargPos = (Double.NaN, Double.NaN, Double.NaN), KAIMoveParams ExtraParams = Null])

Parameters:

  • Other: The actor to run away from.
  • Attempts: How many positions to try per next position picked. Default is 32.
  • RunRad: The radius around which to find a viable position to run away to. Default is 128 map units.
  • MaxSteps: How many steps the actor is allowed to take before having to find a new position to move away to. Default is 32.
  • DetourFactor, AngleLimit, ChaseFlags, Flags: These parameters work the same as in KAI_MoveTowards()
  • KMAFlags: Passes flags exclusive to this function like
  • TargPos: If this vector isn't empty, it will be used in place of running away from Other, useful for making the actor run away from a position instead of an actor. Like for running away from hazards. NaN by default. Requires Other to be null as well to work properly.
  • Params: Passes parameters from the KAIMoveParams struct for the actor to use. The parameters used by KAI_MoveAway() itself and what they do can be found here.

Return type(s):

  • None

Function:

Makes the NPC run away from the Other actor, similar to how A_Chase()/NewChaseDir() makes the NPC move away from their target if the target is scary or they are scared. Except this is a separate function, and more sophisticated too. Picking positions away from Other to actually move to, instead of just inverting the movement direction. Actors reach the position they are supposed to run away to once they are within MeleeRange of it, similar to ZDoom patrol points.

Running behind corners

The function can also allow for making NPCs that are retreating run away to the closest corner cover to their left or right, where the Other or TargPos they're running from has no direct line of sight nor can walk in a straight line to reach them. The max distance the function can check and how many substeps the check can be split to (To find the closest covered substep) can be controlled by passing the CornerDist and CornerDiv variables to a KAIMoveParams struct, respectively.

Obstacle avoidance

The function also allows NPCs to try avoiding obstacles in front of them, instead of bumping into them then trying to squirm around said obstacle. Which should in theory allow them to more elegantly avoid said obstacles than the stock KAI_MoveTowards() allows. The check runs from the left to right. The distance to check in front of the actor and how many slices around the actor to split the checks to (To make them move to the first unobstructed step) can be controlled by passing the ObstacleDist and ObstacleSlices variables to a KAIMoveParams struct, respectively. This feature just works by using KAI_AvoidObstacles().

See also

Clone this wiki locally