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
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
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