Skip to content

Humanoid functions

inkoalawetrust edited this page Oct 11, 2024 · 6 revisions

NOTE: For a list of functions shared by both vehicles and humanoids, look here !

These are the ZScript functions available to intelligent non-vehicle NPCs.

KAI_HandleCrouching()

NOTE: This function only handles dynamically changing the actors' height, it doesn't do any necessary visual changes !

Parameters:

  • UncrouchedHeight: The standard height at which the actor stays uncrouched at, usually this is simply the actors' Default.Height.
  • CrouchedHeight: The height which the actor can down crouch to.
  • ChangeHeight: Should the actors' height actually be altered at all ? Default is true.

Return type(s):

  • Returns true if the caller needs to crouch. Generally the return is passed to a boolean that tracks if the actor is crouching currently.

Function:

Handles changing the height of an actor by checking if their next step is blocked, if the obstacle is closer down than UncrouchedHeight, but taller than CrouchedHeight, then the actor will change their height to the latter value to crouch under the obstacle. This function can account for 3D floors, blocking actors, and normal sector ceilings.

Example:

The function updates automatically, so the only real setup needed is something like this:

Crouching = KAI_HandleCrouching()

But it doesn't actually handle any necessary visual changes. To change how the actor looks, you can keep track of what the function returns, to dynamically alter the actors' sprites every time they move, for example, if the crouched and uncrouched sprites are in separate sprite names (e.g MARC and MARF, respectively), then dynamically changing the sprites can be as simple as this:

If (Crouching) Sprite = GetSpriteIndex ('MARC');

Worst case scenario, the crouching sprites are in different animation frames, in that case, remapping the frames themselves will be needed, like shown below:

				//Wiki note, in this case, the uncrouched move sprites are MARF JKLM, and have to be remapped to MARC ABCD.
				If (Crouching) //Remap movement animation, the actual hitbox change is handled by SM_Chase().
				{
					Sprite = GetSpriteIndex ('MARC');
					//Remap sprite frames, man this shit looks incomprehensible if you don't have like 4 years of experience making GZDoom mods.
					Switch (Frame)
					{
						Default:
							Break;
						Case 9: //J
							Frame = 0; //A
							Break;
						Case 10: //K
							Frame = 1; //B
							Break;
						Case 11: //L
							Frame = 2; //C
							Break;
						Case 12: //M
							Frame = 3; //D
							Break;
					}
				}

KAI_HandleClimbing()

Parameters:

  • ClimbToPos: A reference to a vector3 which will be set to the position the function has determined the caller needs to climb up to. Pass Null to this if it's not needed, for some reason.
  • JumpToPos: Ditto, but with the position the caller should jump too if the ledge is 'just' out of reach.
  • ClimbState: The state the NPC should go to so they can climb up, if any, default is Climb. Passing Null (No quotes) will not trigger a jump.
  • JumpState: Ditto, but with a state for the actor to jump to (As in, an actual jump sequence, not a state to go to).
  • ClimbMul: If the ledges' height is under the callers' height * ClimbMul, the actor will pass a ClimbToPos and go to the ClimbState. Default is 1.1.
  • JumpClimbMul: If the ledges' height is above Height*ClimbMul, but at or under this multiplier of the NPCs' height, they will use their JumpToPos and JumpState to reach close to the height first.

Return type(s):

  • Returns true if the NPC should climb. While 'ClimbToPos' and 'JumpToPos' act as returns for the positions to climb and/or jump to.

Function:

Allows the NPC to climb over ledges below a certain height, including blocking actors, solid dead NPCs (Will not climb over living ones), 3D floors, 3D middle textures, and normal level geometry. In addition, a second height, vector, and state can be specified, that allows the caller to jump and then grab the ledge, for ledges barely out of reach.

Example:

This is how my Smart Marine NPC handles climbing in their SM_Chase() function:

				If (!Crouching)
				{
					If (KAI_HandleClimbing(ClimbPos,JumpPos,"Climb","Jump.Up",1.1,1.75))
						MovedAlready = True;
				}

'ClimbPos' and 'JumpPos' are the vector3s that keep track of where he should climb and jump to, respectively, and are passed by reference so that the function can update them.

KAI_LineBlocksClimb()

Parameters:

  • Which: The linedef to check.

Return type(s):

  • Returns true if the line would block the callers' climb.

Function:

Checks if the line in question would block the actor trying to climb. Used by KAI_HandleClimbing().

KAI_FindClimbable3DFloor()

Parameters:

  • Dist: How far ahead of the caller to check for 3D floors.
  • Iterations: How many traces should be fired from the top of the actor to the bottom. Default is 4. More iterations will lead to more accurate checks but have more overhead.

Return type(s):

  • Returns a pointer to the 3D floor in the way, if any.

Function:

Checks and returns any 3D floor in the callers' way, despite the name, this is not only used by KAI_HandleClimbing(), but also by KAI_HandleClimbing().

KAI_GetJumpPosition()

Parameters:

  • CheckDistance: How far ahead of the caller should the check proceed.
  • CheckAngle: The angle to fire the check across, normally this would just be the NPCs' current angle.

Return type(s):

  • Returns a Vector2 of the position that is on the other side of a ledge, if it fails, it returns a null/NaN vector instead.

Function:

This function is used to check if there are gaps in front of the calling NPC that are larger than its' MaxStepHeight, these includes normal sector pits, 3D floors, blocking actors, or any combination thereof, and returns the position that it found at the end of the ledge that isn't lower than the MaxStepHeight, like the end of the pit or a platform. If the final check that is fired CheckDistance away is still in the pit. There is something blocking the NPCs' way, or the jump is less distant than the callers' radius (Meaning that they can likely just walk over it), then it returns a null vector instead. Which can be for with vecname == vecname if the vector is NOT invalid.

KAI_JumpTo()

Parameters:

  • Where: The vector3 position for the actor to jump to.
  • JumpSpeed: How fast to jump to Where, positive values are the exact velocity the NPC is flung at, negative ones are scaled linearly between the NPCs' position and the MaxLength, allowing the actor to try and avoid overshooting shots. Default is -17.2 (Just enough to cross a 288 MU/9 meter pit, the real world human limit).
  • MaxLength: The max length of the jump, used to linearly scale the callers' JumpSpeed based on the position of the jump destination.

Function:

Makes the actor jump to Where by flinging themselves at the destination. Allowing NPCs to actually jump to different positions.

Clone this wiki locally