Skip to content

Data type

Ray

Official docs ↗

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

About Ray

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

  • Ray.new(Origin: Vector3, Direction: Vector3)Returns a Ray with the given Origin and Direction.

Properties 3

  • Unit: RayThe Ray with a normalized direction (the direction has a magnitude of 1).
  • Origin: Vector3The position of the origin.
  • Direction: Vector3The direction vector of the Ray.

Methods 2

  • ClosestPoint(point: Vector3) → Vector3Returns a Vector3 projected onto the ray so that it is within the Ray line of sight.

    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!

  • Distance(point: Vector3) → numberReturns the distance between the given point and the closest point on the Ray.

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

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.