A ray has one origin point in the 3D scene and a direction. It returns potentials Impacts and the distance from the origin when that happens.


Ray ( Number3 origin, Number3 direction )

Creates a Ray with an origin and a direction.

local ray = Ray(Camera.Position, Camera.Forward)
local impact = ray:Cast()


Impact Cast ( Shape filterIn )
Impact Cast ( nil filterIn, Object filterOut )
Impact Cast ( CollisionGroups filterIn, Object filterOut )
Impact Cast ( Shape filterIn, Object filterOut )

Casts a ray and returns an Impact (can be nil).

The Impact contains information about what's been hit.

By default, a ray collides with all CollisionGroups. But filters can be set, if you want your ray to only collide with the Map for example. You can also filter out an Object of any kind.

Pointer.Down = function( pointerEvent )
    local ray = Ray(pointerEvent.Position, pointerEvent.Direction)
    local impact = ray:Cast()
    if impact.Block ~= nil then
      print("block hit:", impact.Block)

-- cast rays from Camera's position to remove cubes in the map
Client.Action2 = function()
    local ray = Ray(Camera.Position, Camera.Forward)
    ray:Cast(Map.CollisionGroups) -- only consider the map for collisions
    if impact.Block ~= nil then

-- cast ray down from Player's position to see
-- if there's something under it:
Client.Action3 = function()
    local ray = Ray(Player.Position, {0, -1, 0})
    ray:Cast(nil, Player) -- filter out Player to avoid direct impacts with it
    if impact ~= nil then
        print("found something under the player, distance:", impact.Distance)


The direction of the ray, in world coordinate system.

Defines items colliding with the ray. nil by default, meaning the ray collides with everything.

nil by default. Can be set to an Object to filter it out from possible collisions.

The origin of the ray, in world coordinate system.