Ray

Constructors

NameDescription
new(origin: Vector3,direction: Vector3)Constructs a new Ray with the given origin point and direction vector. The direction vector's length determines how far the ray extends.

Code Snippet

local origin = Vector3.new(0, 10, 0)
local direction = Vector3.new(0, -1, 0) * 50

local ray = Ray.new(origin, direction)

local target = Vector3.new(0, 0, 5)
print("Closest point on ray:", ray:ClosestPoint(target))
print("Distance from ray:", ray:Distance(target))

Properties

NameTypeDescription
OriginVector3The position where the ray begins.
DirectionVector3The directional vector of the ray, including its length.
UnitRayThe same ray with its Direction normalized to a magnitude of 1, keeping the same Origin.

Methods

NameParametersReturnsDescription
ClosestPoint(point: Vector3):Vector3Point: Vector3Vector3Returns the point on the ray that is closest to the given point. Requires a unit ray (see the Unit property) to behave correctly.
Distance(point: Vector3):numberPoint: Vector3numberReturns the shortest distance between the given point and its closest point on the ray.