-
Notifications
You must be signed in to change notification settings - Fork 0
KAI_MoveAway()
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])
- 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
- KMA_STRAIGHT: The NPC will move away from Other in a straight line instead of picking a random position furthest away from Other.
- 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.
- None
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. If KMT_3D is passed as a flag, then this function will make the actor move away in 3D.
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. This feature just works by using KAI_CheckCorners().
In 3D mode, KAI_MoveAway() will use KAI_CheckCorners3D() instead. Which checks around the flying actor in a vertical clock-like pattern, but otherwise behaves similarly to the left and right checks of its' 2D counterpart. KAIMoveParams' CornerDist and CornerDiv do the same thing, but you also need to use CornerSlices, which determines how many slices the check projects around the actor, think of it like a vertical version of what the 2D obstacle avoidance does.
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().
Obstacle avoidance for flyers works very differently. It instead fires a sphere of traces around the actor, and getting an average of the end spots for all of them, so if a bunch hit an obstacle and end prematurely, the average is skewed away from said obstacle. Then it shoves the flier towards that averaged position away from any obstacles, after each step away from whatever it's running from. The speed at which KAI_MoveAway() pushes the actor to the avoidance position every step can be set with ObstacleSpeed. This uses KAI_AvoidObstacles3D(). Below is a list of what KAI_AvoidObstacles3D() parameter each relevant variable in KAIMoveParams maps to:
HorzTraces -> ObstacleSlices
VertTraces -> ObstacleDiv
Distance -> ObstacleDist
Threshold -> ObstacleThreshold
Magnitude -> ObstacleMagnitude
MinDist -> ObstacleMinDist
- Home
- Features
- Classes
- Functions
- Guides