Ray

Overview

Ray represents an invisible ray extending infinitely in a specified direction from a starting point in 3D space. This data type does not perform collision detection and is used to configure input values for direction-based calculations or performing Raycasts.

Constructors

new

Creates a new Ray with the provided starting point (Origin) and Direction. The created Ray starts at the specified position and extends infinitely along the set direction.

Parameters

Vector3 InOrigin

Specifies the position in 3D space where the Ray starts. This value becomes the reference point of the ray.

Vector3 InDirection

The direction vector indicating the direction the Ray will travel. Typically uses a normalized vector, and the Ray extends infinitely in this direction.

Return

Ray

A Ray created based on the specified origin and direction.

Code Samples

local Origin = Vector3.new(0, 50, 0)
local Direction = Vector3.new(0, 0, -1)
local Ray = Ray.new(Origin, Direction)
print(Ray)

Properties

Origin

Vector3

This value represents the point where the Ray starts, defining the reference position in 3D space from which the ray originates.

Code Samples

Direction

Vector3

Defines which direction the Ray travels in, providing the directional reference along which the ray extends from the origin. This is a key element determining the Ray's direction of travel in 3D space.

Code Samples

Unit

Ray

Represents a Ray with a normalized direction vector, where the size of direction is always 1.

Code Samples

Methods

ClosestPoint

Calculates and returns a vector converted to the closest position along the Ray's direction of sight based on the Ray's origin and direction from the provided coordinates. This allows determining where a specific point is located along the Ray's line of sight and can be used for direction-based position calculations or distance detections.

Parameters

Vector3 InPoint

A point in 3D space that serves as the target for calculating the closest position based on the Ray. This point is projected based on the Ray's origin and direction for calculation.

Return

Vector3

Returns the 3D coordinates corresponding to the closest position on the Ray for the provided point. The returned value is a point located on the Ray's line of sight.

Code Samples

Distance

Calculates the closest point on the Ray based on the provided coordinates, then returns the distance between the two points. In other words, it provides the straight-line distance between the position obtained through ClosestPoint and the original point, and can be used for a distance detection between a Ray and a specific point.

Parameters

Vector3 InPoint

A point in 3D space that serves as the reference for calculating distance to the Ray. The closest point on the Ray is calculated based on this point.

Return

number

Returns the shortest distance between the provided point and the Ray. This is the straight-line distance between the original point and the closest point on the Ray obtained through ClosestPoint.

Code Samples

Last updated