Roblox UtilitiesDevlHub Roblox Documentation

Data type

Ray

Represents a line with a starting point that casts infinitely in a specific direction.

The Ray data type represents a half-line, finite in one direction but infinite in the other. It can be defined by a 3D point, where the line originates from, and a direction vector, which is the direction it goes in.

Constructors 1#

newReturns a Ray with the given Origin and Direction.

new(Origin: Vector3, Direction: Vector3)#

Returns a new Ray with given Origin and Direction.

NameTypeDefaultDescription
OriginVector3The starting point of the ray in 3D space.
DirectionVector3The direction vector of the ray. Does not need to be a unit vector.

Properties 3#

UnitRayThe Ray with a normalized direction (the direction has a magnitude of 1).
OriginVector3The position of the origin.
DirectionVector3The direction vector of the Ray.

Unit: Ray#

The Ray with a normalized direction (the direction has a magnitude of 1).

Origin: Vector3#

The position of the origin.

Direction: Vector3#

The direction vector of the Ray.

Methods 2#

ClosestPointReturns a Vector3 projected onto the ray so that it is within the Ray line of sight.
DistanceReturns the distance between the given point and the closest point on the Ray.

ClosestPoint(point: Vector3): Vector3#

Returns a Vector3 projected onto the ray so that it is within the Ray line of sight.

Note: the Ray must be a unit ray for this method to behave as expected!

NameTypeDefaultDescription
pointVector3The point in 3D space to project onto the ray.
Returns
  • Vector3 — The point on the ray closest to the given point, or the ray origin if the projection falls behind it.

Distance(point: Vector3): number#

Returns the distance between the given point and the point on the ray nearest to the given point (Datatype.Ray.ClosestPoint(point)).

NameTypeDefaultDescription
pointVector3The point in 3D space to measure distance from.
Returns
  • number — The shortest distance between the given point and the closest point on the ray.