Ray
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.
Constructors
Creates a Ray with an origin and a direction.
local ray = Ray(Camera.Position, Camera.Forward) local impact = ray:Cast()
Functions
Impact Cast ( CollisionGroups filterIn )
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) end end -- cast rays from Camera's position to remove cubes in the map Client.Action2 = function() local ray = Ray(Camera.Position, Camera.Forward) local impact = ray:Cast(Map.CollisionGroups) -- only consider the map for collisions if impact.Block ~= nil then impact.Block:Remove() end end -- 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}) local impact = 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) end end
-- When a single Shape is provided -- the Shape's internal block touched is provided -- as part of the Impact object Client.Action2 = function() local ray = Ray(Camera.Position, Camera.Forward) local impact = ray:Cast(myShape) -- only consider a Shape for collisions -- impact.Block is Number3(0, 5, 12) -- impact.Distance is 42,72234 -- impact.Object is the `myShape` Shape end
Properties
Defines items colliding with the ray. nil by default, meaning the ray collides with everything.