Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding coordinates are wrong?

Asked by 7 years ago

In my game I have a script which acts as a sort of 'GPS' system. It seems to work, except for when I go under terrain. Under the terrain it starts throwing some errors at me, Enum.PathStatus.ClosestOutOfRange a lot. This happens when I am only 5 studs away from the destination. Neither ComputeRawPathAsync or ComputerSmoothPathAsync fixes this error. Here are the main parts involved:

Contextual information: x is the x cordinate, y is the z coordinate, and pathw is a frame for inputting the values.

(the triggering event)

coords = CFrame.new(pathw.x.Text,math.floor(pathw.depth.Text)+218,pathw.y.Text)
    print(coords)
    path = game:GetService("PathfindingService"):ComputeRawPathAsync(game.Players.LocalPlayer.Character.Torso.CFrame.p,coords.p,512)

(the loop)

    local model = Instance.new("Model",game.Workspace.CurrentCamera)
while wait() do
    model:ClearAllChildren()
    if started then

        --path = game:GetService("PathfindingService"):ComputeRawPathAsync(game.Players.LocalPlayer.Character.Torso.CFrame.p,coords.p,512)
        if path.Status~=Enum.PathStatus.Success then
            game.StarterGui:SetCore("SendNotification", {
            Title = "Error!"; 
            Text = "Something went wrong in your path.. it might fix itself though, so just ignore this message"; 
            Icon = ""; 
            Duration = 5;
        })
        end
        pathc = path:GetPointCoordinates()
        for i=1,20 do
            if pathc[i] then
            local part = Instance.new("Part",model)
            part.Size= Vector3.new(1,1,1)
            part.CanCollide=false
            part.Transparency = 1
            part.TopSurface= "Smooth"
            part.BottomSurface = "Smooth"
            part.Transparency = 0.5
            part.Material ="Neon"
            part.Anchored=true
            part.Shape="Ball"
            part.CFrame = CFrame.new(pathc[i])
            end 
        end
    end
end

Thanks

Answer this question