How to make NPC's jump?

so i forgor how to make npc’s jump, i have no idea what to do and i cant find anything on it.

code:

local npc = script.Parent 

local function wanderAroundPoint(point, radius)
	local angle = math.rad(math.random(0, 360))
	local distance = math.random(0, radius)
	local offsetX, offsetZ = math.cos(angle) * distance, math.sin(angle) * distance
	local randomPoint = Vector3.new(point.X + offsetX, point.Y, point.Z + offsetZ)

	local path = game:GetService("PathfindingService"):CreatePath({
		AgentRadius = 2,
		AgentHeight = 5,
		AgentCanJump = true,
		AgentJumpHeight = 10,
		AgentMaxSlope = 45,
	})
	path:ComputeAsync(npc.PrimaryPart.Position, randomPoint)

	local waypoints = path:GetWaypoints()
	for _, waypoint in ipairs(waypoints) do
		npc.Humanoid:MoveTo(waypoint.Position)
		npc.Humanoid.MoveToFinished:Wait() -- Wait for the NPC to reach the waypoint
	end
end

while true do
	wait(0.5)
	wanderAroundPoint(Vector3.new(0,0,-120), 100)
end

please tell me what to do or what i did wrong!
(i have the Humanoids jumps setting enabled and even tried to krank the jumpheight up, but that didnt do anything.)

Waypoints have a PathWaypointAction Enum named Enum.PathWaypointAction.Jump which you can use to detect when the NPC needs to jump to reach the next waypoint, then you can set its Humanoid’s Jump property to true and change its state to Jumping


@1gotba_nned0 You can read the Enum value by reading the waypoint’s Action property within the for loop

2 Likes

thanks man :slight_smile:
could also tell me where i define a variable to the jump-action-thingy?
do i get it with like WAYPOINT.action or smth or?

1 Like

Something like this should work to achieve what you’re looking for:

local npc = script.Parent 

local function wanderAroundPoint(point, radius)
	local angle = math.rad(math.random(0, 360))
	local distance = math.random(0, radius)
	local offsetX, offsetZ = math.cos(angle) * distance, math.sin(angle) * distance
	local randomPoint = Vector3.new(point.X + offsetX, point.Y, point.Z + offsetZ)

	local path = game:GetService("PathfindingService"):CreatePath({
		AgentRadius = 2,
		AgentHeight = 5,
		AgentCanJump = true,
		AgentJumpHeight = 10,
		AgentMaxSlope = 45,
	})
	path:ComputeAsync(npc.PrimaryPart.Position, randomPoint)

	local waypoints = path:GetWaypoints()
	for _, waypoint in ipairs(waypoints) do
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			npc.Humanoid.Jump = true
			npc.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end

		npc.Humanoid:MoveTo(waypoint.Position)
		npc.Humanoid.MoveToFinished:Wait() -- Wait for the NPC to reach the waypoint
	end
end

while true do
	wait(0.5)
	wanderAroundPoint(Vector3.new(0,0,-120), 100)
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.