Flying pathfinding npc bug (Solved)

So im having an issue with a pathfinding NPC that follows the player, it is made to jump over parts and keep following the player, but when it does jump over the parts, it goes flying up into the air and stays up there. Couldn’t find anyone with the same issue

video:
robloxapp-20240217-2157299.wmv (2.5 MB)

code:

local zombtorso = script.Parent.Torso
zombtorso:SetNetworkOwner(nil)
local zombhumanoid = script.Parent:WaitForChild("Humanoid")
local pathfindingservice = game:GetService("PathfindingService")

local function findtarget()
	local aggrodistance = 50
	local target = nil
	for i, v in pairs(game.Workspace:GetDescendants()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso")
		if human and torso and v ~= script.Parent then
			if (zombtorso.Position - torso.Position).Magnitude < aggrodistance then
				aggrodistance = (zombtorso.Position - torso.Position).Magnitude
				target = torso
			end
		end
	end
	return target
end

while task.wait() do
	local torso = findtarget()
	if torso then
		local path = pathfindingservice:CreatePath()
		path:ComputeAsync(zombtorso.Position, torso.Position)
		local waypoints = path:GetWaypoints()
		for i, v in pairs(waypoints) do
			if v.Action == Enum.PathWaypointAction.Jump then
				zombhumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			zombhumanoid:MoveTo(v.Position)
		end
	end
end

nvm i found a fix to it so i dont need help

Please provide the solution you found in a reply. This post could potentially help out someone with the same issue in the future.

1 Like

my code

local zombtorso = script.Parent.Torso
zombtorso:SetNetworkOwner(nil)
local zombhumanoid = script.Parent:WaitForChild("Humanoid")
local pathfindingservice = game:GetService("PathfindingService")

local function findtarget()
	local aggrodistance = 50
	local target = nil
	for i, v in pairs(game.Workspace:GetDescendants()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso")
		if human and torso and v ~= script.Parent then
			if (zombtorso.Position - torso.Position).Magnitude < aggrodistance then
				aggrodistance = (zombtorso.Position - torso.Position).Magnitude
				target = torso
			end
		end
	end
	return target
end

while task.wait() do
	local torso = findtarget()
	if torso then
		local path = pathfindingservice:CreatePath()
		path:ComputeAsync(zombtorso.Position, torso.Position)
		local waypoints = path:GetWaypoints()
		
		for index, waypoint in pairs(waypoints) do
			par = Instance.new("Part", workspace)
			par.Size = Vector3.new(1, 1, 1)
			par.Color = Color3.fromRGB(0, 255, 155)
			par.Material = "Neon"
			par.Position = waypoint.Position
			par.CanCollide = false
			par.Anchored = true
			par.Name = "WaypointZ"
		end
		
		for i, v in pairs(waypoints) do
			if v.Action == Enum.PathWaypointAction.Jump then
				zombhumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			zombhumanoid:MoveTo(par.Position)
			zombhumanoid.MoveToFinished:Wait()
		end
	end
end
1 Like

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