Hey developers! I have a Agent that I want to move from one point to another logically.
Sometimes these paths that are computed by PathFindingService are Unnatural (which normally means to me I’m doing something wrong)
Normally, I would expect a service like this to have the Fastest path from Point A to Point B, Following the table of parameters for the Agent
However I keep getting weird results like this (Where it doesn’t go straight, goes right before going left):
(Starting Point (Point A) is the bottom part, Ending Point (Point B) is the part at the top of image. Red spheres are the Waypoints generated)
I don’t understand why it’s not taking the shortest path, and I don’t have any Costs… Here is mt code below:
-- Code that do not relate to generating and applying the path are left out for easy reading
local PathfindService = game:GetService("PathfindingService")
local TheMainPath : Path = PathfindService:CreatePath({AgentRadius = 2, AgentHeight = 10, AgentCanJump = false})
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
repeat
if script.CurrentLocation.Value ~= nil then
local WhereToList = {} -- List of Parts
TheMainPath:ComputeAsync(script.Parent:GetPivot().Position, WhereToList[math.random(1, #WhereToList)])
else
TheMainPath:ComputeAsync(script.Parent:GetPivot().Position, game.Workspace.WriteCharmsMovementPoints.StartPoint.Position)
end
for i, Location : PathWaypoint in TheMainPath:GetWaypoints() do
print(#TheMainPath:GetWaypoints())
script.Parent.Humanoid:MoveTo(Location.Position)
repeat task.wait() until (script.Parent:GetPivot().Position - Location.Position).Magnitude <= 3
end
task.wait(0.1)
until script.Enabled == false
Any help is much Appreciated!