FANDOM


The Ray class can be used to check for intersection of a ray with a particular model, map or plane.

Ray:NewEdit

[Ray] Ray:New( [Vector3] position, [Vector3] direction )

Returns a new ray

Ray:IntersectsPlaneEdit

[number or nil] Ray:IntersectsPlane( [Plane] plane )

Returns the distance of intersection of the ray with the specified Plane (or nil if there is no intersection)

Ray:IntersectsModelRendererEdit

[number or nil], [Vector3 or nil] Ray:IntersectsModelRenderer( [ModelRenderer] modelRndr )

Returns the distance of intersection of the ray with the specified ModelRenderer (or nil if there is no intersection) and the normal of the hit face.

Example: Computing the hit positionEdit

-- Setup a ray pointing forward
​local ray = Ray:New( self.gameObject.transform:GetPosition(), Vector3.Transform( Vector3:New( 0, 0, -1 ), self.gameObject.transform:GetOrientation() ) )

-- Assuming we have a model renderer component in "modelRndr", let's cast our ray
local distance = ray:IntersectsModelRenderer( modelRndr )

-- Check if we got a hit
if distance ~= nil then
    -- Compute the position of the hit using the distance and print it
    local hitPosition = ray.position + ray.direction * distance
    print( "Hit at " .. hitPosition )
end

Ray:IntersectsMapRendererEdit

[number] distance, [Vector3] normal, [Vector3] hitBlockLocation, [Vector3] adjacentBlockLocation Ray:IntersectsMapRenderer( [MapRenderer] mapRndr )

Returns the distance of intersection of the ray with the specified MapRenderer (or nil if there is no intersection). Additional return values are the normal of the hit face, and the locations in the map of the hit and adjacent map blocks.

Warning: If your ray is at the exact intersection of two map blocks, it will not reliably return the hit distance. As a workaround, you can try avoiding perfectly aligned rays or shooting precisely between two blocks. This should be fixed in a future update.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.