I want my pathfinding character to go to the most obvious route, which in this case should be straight, but for some reason the path does not go straight. I have tried changing the WaypointSpacing parameter but that gave the same result. Is there a solution for this?
local PFS = game:GetService("PathfindingService")
local DebrisFolder = game.Workspace:WaitForChild("Debris")
local Zombie = script.Parent:WaitForChild("Zombie")
local Target = script.Parent:WaitForChild("Target")
local Humanoid = Zombie:WaitForChild("Humanoid")
local RootPart0 = Zombie:WaitForChild("HumanoidRootPart")
RootPart0:SetNetworkOwner(nil)
local function CreateVisual(WaypointPosition)
local Part = Instance.new("Part", DebrisFolder)
Part.Position = WaypointPosition
Part.CanCollide = false
Part.CanQuery = false
Part.CanTouch = false
Part.Anchored = true
Part.Material = Enum.Material.Neon
Part.Shape = Enum.PartType.Ball
Part.Size = Vector3.new(0.5,0.5,0.5)
Part.Color = Color3.fromRGB(255,255,255)
end
local Path = PFS:CreatePath({
AgentCanClimb = true,
})
local Success, Error = pcall(function()
Path:ComputeAsync(RootPart0.Position, Target.Position)
end)
if Success and Path.Status == Enum.PathStatus.Success then
for _, Waypoint in pairs(Path:GetWaypoints()) do
local Visual = CreateVisual(Waypoint.Position)
if Waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
else
print(Error)
end