We use cookies on this site to enhance your user experience

Check if a point is visible

Check if a point is visible

Sep 06 2018, 2:15 AM PST

The following function returns true if a DataType/Vector3 is visible on screen and unobscured by BasePart|BaseParts and Terrain.

local function isPointVisible(worldPoint)
    local camera = workspace.CurrentCamera
    local vector, onScreen = camera:WorldToViewportPoint(worldPoint)
    
    if onScreen then
        local origin = camera.CFrame.p
        local ray = Ray.new(origin, worldPoint - origin)
        local hit = workspace:FindPartOnRay(ray)
        if hit then
            return false
        end
    else
        return false
    end
    return true
end