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

How do i use the CheckOcclusionAsync in PathfindingService?

Asked by 7 years ago

Hello, I was really confused about the CheckOcclusionAsync, I check the wiki but there is no answer about using it. Can someone know how to use it? Here's the script that use in wiki but I modified it withCheckOcclusionAsync.

-- In Script in ServerScriptService

local pathfindingService = game:GetService("PathfindingService")
local pointModel = Instance.new("Model")
pointModel.Name = "Points"
pointModel.Parent = game.Workspace

-- Setup remote function
local remoteFunction = Instance.new("RemoteFunction")
remoteFunction.Parent = game.ReplicatedStorage

function visualizePath(path)
    -- clear old path visualization
    pointModel:ClearAllChildren()

    -- calculate new visualization  
    local points = path:GetPointCoordinates()
    for _, point in ipairs(points) do
        local part = Instance.new("Part")
        part.Parent = pointModel
        part.FormFactor = Enum.FormFactor.Custom
        part.Size = Vector3.new(1,1,1)
        part.Position = point
        part.Anchored = true
        part.CanCollide = false
    end
end

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, target)
    local start = player.Character.Torso.Position
    local path = pathfindingService:ComputeSmoothPathAsync(start, target, 500)
    local checkPath = pathfindingService:CheckOcclusionAsync() -- This is the problem

    visualizePath(path)
    -- Check to see if the path was computed correctly
    if path.Status == Enum.PathStatus.FailStartNotEmpty or path.Status == Enum.PathStatus.FailFinishNotEmpty then
        print("Compute failed")
        return {}
    end

    return path:GetPointCoordinates()       
end

Thank You.

Answer this question