FindObjOnRay

Constructor:

FindObjOnRay(ray,ignoreInstance)

Description

Emits a ray, and returns the first part object that it touches, the position of the touch point and the normal of the touch surface.

Parameter

Name Class Name Description
ray Ray Ray
ignoreInstance RWObject Objects to ignore

Return Value

Class Name Description
RWObject Object that the ray hits.
Vector3 Position of the ray collision point.
Vector3 A normal to the touch surface through the ray collision point

Examples

Continuously emit rays from the camera to the mouse position, ignoring the objects in the table. When the rays hit an object, the object changes color. Observe whether the printed return value is correct or not.

local function MyUpdate()
    local ray = WorkSpace. Camera: ScreenToRay(Mouse.MousePosition)
    local e,p,n = WorkSpace:FindObjOnRay(ray,WorkSpace. NewBackground)
    if e~=nil then
        e.Color = Vector3.New(255,0,0)
        print(tostring(e.Name))
        print(tostring(p))
        print(tostring(n))
    end
end    
local function coroutineUpdate()
    while true do
        coroutine.wait(1)
        MyUpdate()
    end
end
coroutine.start(coroutineUpdate)