Ray: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
initial from forum posts/experiments
 
>GoldenUrg
initial from forum posts/experiments
(No difference)

Revision as of 22:22, 8 May 2010


Description

A Ray is a 3-D point and a direction.

Usage

The Ray objects main purpose seems to be to act as a basis for Ray tracing. Its methods allow comparison of Ray against other 3-D points.

For example you can detect if a Ray intersects a sphere:

function intersect_sphere( ray, sphere_position, sphere_radius )
  return ray:Distance( sphere_position ) <= sphere_radius
end

To check if your target is pointing at a sphere (even if other things are in the way):

if intersect_sphere( mouse.UnitRay, sphere.Position, sphere.Size.X ) then
  -- do on hit
end

Constructors

Constructor Description
Ray.new(Origin, Direction) Creates a new Ray with given Origin and Direction.

Methods

Member Function Description
Ray:ClosestPoint(Vector3 point) Returns the closest point on the Ray to point. Note Rays are unidirectional.
Ray:Distance(Vector3 point) Returns the distance from point to ClosestPoint(point)

Properties

All of these properties are Read Only (you can't just set them Vector3.x = 5, it doesn't work) but you can create new

Property Type Description
Vector3.Origin Vector3 The Origin position
Vector3.Direction Vector3 The Direction vector

Limitations

Advanced Note: Technically the direction need not be a unit vector, but most Ray methods assume it is.

See Also