Hand-written by Joseph San Nicolas, Roblox Developer
Ray
Constructors
| Name | Description |
| 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
| Name | Type | Description |
| Origin | Vector3 | The position where the ray begins. |
| Direction | Vector3 | The directional vector of the ray, including its length. |
| Unit | Ray | The same ray with its Direction normalized to a magnitude of 1, keeping the same Origin. |
Methods
| Name | Parameters | Returns | Description |
| ClosestPoint(point: Vector3):Vector3 | Point: Vector3 | Vector3 | Returns 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):number | Point: Vector3 | number | Returns the shortest distance between the given point and its closest point on the ray. |