FindObjOnRayWithWhitelist

Constructor:

FindObjOnRayWithWhitelist(ray,whiteTable)

Description

The variant of FindPartOnRay, only checking the objects in the input table.

Parameters

Name Type Description
ray Ray Ray.
whiteTable table Objects to check

Return Value

Type Description
table List of the found objects

Examples

Create a part named it part1 in WorkSpace. Continuously emit rays from the camera to the mouse position, only checking the objects in the table. When the rays hit an object in the table, the object changes color. Observe whether the printed return value is correct.

local function MyUpdate()
    local ray = WorkSpace. Camera: ScreenToRay(Mouse.MousePosition)
    local mt = {WorkSpace. part1} -- part1 in WorkSpace
    local e = WorkSpace:FindObjOnRayWithWhitelist(ray,mt)
    if e then
        e.entity.Color = Vector3.New(255,0,0)
        print(tostring(e.entity.Name))
        print(tostring(e.Point))
        print(tostring(e.Normal))
    end
end
    
local function coroutineUpdate()
    while true do
        coroutine.wait(0.1)
        MyUpdate()
    end
end

coroutine.start(coroutineUpdate)