Skip to content

KAI_MoveTowards()

inkoalawetrust edited this page Sep 15, 2023 · 5 revisions

KAI_MoveTowards (Vector3 TargetPos[, Double DetourFactor = 1.0, Double AngleLimit = 10, Int ChaseFlags = 0, Int Flags = 0])

Parameters:

  • TargetPos: The Vector3 coordinate that the actor should move towards.
  • DetourFactor: How much the actor is allowed to move around an obstacle after hitting one, before beginning to head towards TargetPos again. Actors take 16 to 32 steps by default, this is a multiplier for that. Default is 1.0.
  • AngleLimit: How wide of a turn in degrees the actor can take per step. A value of 0 makes the actor take instant 180 degree turns. Default is 10.
  • ChaseFlags: What flags from A_Chase should the function use ? Supports CHF_DONTMOVE, CHF_NODIRECTIONTURN, CHF_NORANDOMTURN, and CHF_STOPIFBLOCKED.
  • Flags:
    • KMT_CHASEGOAL: If the caller has a goal pointer, and the bChaseGoal flag on. It will follow the goal instead of the TargetPos.
    • KMT_ZIGZAG: Causes the NPC to zig-zag when moving around, in a manner similar to KAI_MoveTowards() and A_Chase. Instead of moving towards the TargetPos in a straight line.
    • KMT_NOLINEUSE: The NPC will not use any monster push and use lines it collides with. This can be used to allow monsters to run their own line use code.

Return type(s):

  • None

Function:

Makes the NPC move to TargetPos. This is THE main movement function for KAI NPCs, all other built-in functions use this to move, and are basically wrappers for it. The function also supports the +CANTLEAVEFLOORPIC flag, treating sectors with different floor textures as obstacles, and using monster pushable and usable lines.

Example:

This Pinky does nothing besides follow the first enemy it sees and play it's active sound.

Class FollowerPinky : KAI_Creature
{
	Default
	{
		Health 150;
		PainChance 180;
		Speed 10;
		Radius 30;
		Height 56;
		Mass 400;
		Monster;
		+FLOORCLIP
		SeeSound "demon/sight";
		AttackSound "demon/melee";
		PainSound "demon/pain";
		DeathSound "demon/death";
		ActiveSound "demon/active";
		Obituary "$OB_DEMONHIT";
		Tag "$FN_DEMON";
	}
	
	States
	{
		Spawn:
			SARG AB 10 A_Look;
			Loop;
		See:
			SARG AABBCCDD 2 Fast
			{
				If (Target)
					KAI_MoveTowards(Target.Pos,detourfactor:0.5);
				KAI_Chase_HandleActiveSound(0);
			}
			Loop;
		}
}

See also

Clone this wiki locally