RaycastHit

Constructor:

RaycastHit(origin,direction,maxDistance)

Description

Creates a ray using the specified start point and direction, and returns the objects it hits, the object names, the hit points and the distances.

Parameters

Name Type Description
origin Vector3 Starting point
direction Vector3 Direction
maxDistance float Maximum distance

Return Value

Type Description
table {string:Name, GameObject:RWObject, Vector3:Point, float:Distance} /*Name: the name of the object that is hit; RWObject: the object that is hit; Point: the coordinates of the object that is hit; Distance: the distance the ray travels*/

Examples

Continuously emit rays from the starting point (0,0,0) along the direction of Vector3(0,0,-10). Output the information of the object that is hit.

local function MyUpdate()
    local origin = Vector3.New(0,3,0)
    local direction = Vector3(0,0,-10)
    local maxDistance = 100
    local list = WorkSpace:RaycastHit(origin,direction,maxDistance)
    if list ~= nil then     
        print(list.Name)
        print(tostring(list.Point))
        print(tostring(list.Distance))
    end
end    
local function coroutineUpdate()
    while true do
        coroutine.wait(0.1)
        MyUpdate()
    end
end

coroutine.start(coroutineUpdate)