Hi, does anybody know why roblox pathfinding makes such sharp turns and how to fix it?
Code:
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
local humanoid = script.Parent.Humanoid
local humanoidrootpart = script.Parent.HumanoidRootPart
local PathFindingService = game:GetService("PathfindingService")
local agentparams = {
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
WaypointSpacing = 1
}
local function getPath(destination)
local path = PathFindingService:CreatePath(agentparams)
path:ComputeAsync(humanoidrootpart.Position, destination.Position)
return path
end
local function getToPlayers()
local target
local players = game.Players:GetPlayers()
for _, plr in pairs(players) do
local char = plr.Character
if char then
local plrhumanoidrootpart = char:FindFirstChild("HumanoidRootPart")
if plrhumanoidrootpart then
if target then
if (humanoidrootpart.Position - plrhumanoidrootpart.Position).Magnitude < 200 then
target = plrhumanoidrootpart
end
else
target = plrhumanoidrootpart
end
end
end
end
if target then
local path = getPath(target)
for i, waypoint in ipairs(path:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid:ChangeState(Enum.HumanoidStateType.Running)
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
end
while true do
getToPlayers()
task.wait()
end