Open Asterune
Vector3

Vector3

Represents a 3-component vector.

Behavior

Vector3 stores X, Y, Z components for positions, directions, and dimensions. Components are read-only. Arithmetic returns new vectors; addition is componentwise and multiplication by a number scales the vector.

Summary

Constructors8
Constants5
  • Vector3.one: Vector3

    The vector (1, 1, 1).

  • Vector3.xAxis: Vector3

    The unit vector (1, 0, 0).

  • Vector3.yAxis: Vector3

    The unit vector (0, 1, 0).

  • Vector3.zAxis: Vector3

    The unit vector (0, 0, 1).

  • Vector3.zero: Vector3

    The constant vector (0, 0, 0).

Functions3
  • Vector3.FromAxis(axis: EnumItem): Vector3

    Returns the unit vector for the specified Cartesian axis.

  • Vector3.FromNormalId(normal: EnumItem): Vector3

    Returns the outward unit normal for the specified Part face.

  • Vector3.new(x: number?, y: number?, z: number?): Vector3

    Creates a vector from X, Y, Z components.

Members16
Properties5
Methods11
  • Abs(): Vector3

    Returns the absolute value of each component.

  • Angle(other: Vector3, axis: Vector3?): number

    Returns the angle to another vector in radians.

  • Ceil(): Vector3

    Returns a vector with each component rounded upward.

  • Cross(other: Vector3): Vector3

    Returns the cross product, perpendicular to both input vectors.

  • Dot(other: Vector3): number

    Returns the dot product.

  • Floor(): Vector3

    Returns a vector with each component rounded downward.

  • FuzzyEq(other: Vector3, epsilon: number?): boolean

    Returns whether the vector components are equal within the supplied tolerance.

  • Lerp(other: Vector3, t: number): Vector3

    Interpolates toward another vector.

  • Max(args: ...Vector3): Vector3

    Returns the component-wise maximum of this vector and the supplied vectors.

  • Min(args: ...Vector3): Vector3

    Returns the component-wise minimum of this vector and the supplied vectors.

  • Sign(): Vector3

    Returns the sign of each component as -1, 0, or 1.

Constructors

FromAxis

Vector3.FromAxis(axis: EnumItem): Vector3

Returns the unit vector for the specified Cartesian axis.

FromNormalId

Vector3.FromNormalId(normal: EnumItem): Vector3

Returns the outward unit normal for the specified Part face.

new

Vector3.new(x: number?, y: number?, z: number?): Vector3

Creates a vector from X, Y, Z components. Omitted components default to 0.

one

Vector3.one: Vector3

The vector (1, 1, 1).

xAxis

Vector3.xAxis: Vector3

The unit vector (1, 0, 0).

yAxis

Vector3.yAxis: Vector3

The unit vector (0, 1, 0).

zAxis

Vector3.zAxis: Vector3

The unit vector (0, 0, 1).

zero

Vector3.zero: Vector3

The constant vector (0, 0, 0).

Properties

Magnitude

Vector3.Magnitude: number

The vector length. The magnitude of the difference between two positions is their distance.

Unit

Vector3.Unit: Vector3

Returns a vector with the same direction and length 1. Check for zero magnitude before normalizing.

X

Vector3.X: number

The X component. Read-only.

Y

Vector3.Y: number

The Y component. Read-only.

Z

Vector3.Z: number

The Z component. Read-only.

Methods

Abs

Vector3:Abs(): Vector3

Returns the absolute value of each component.

Angle

Vector3:Angle(other: Vector3, axis: Vector3?): number

Returns the angle to another vector in radians. An optional axis determines the sign.

Ceil

Vector3:Ceil(): Vector3

Returns a vector with each component rounded upward.

Cross

Vector3:Cross(other: Vector3): Vector3

Returns the cross product, perpendicular to both input vectors.

Dot

Vector3:Dot(other: Vector3): number

Returns the dot product. For nonzero vectors, a positive result indicates an angle below 90 degrees, 0 indicates perpendicular directions, and a negative result indicates an angle above 90 degrees.

Floor

Vector3:Floor(): Vector3

Returns a vector with each component rounded downward.

FuzzyEq

Vector3:FuzzyEq(other: Vector3, epsilon: number?): boolean

Returns whether the vector components are equal within the supplied tolerance.

Lerp

Vector3:Lerp(other: Vector3, t: number): Vector3

Interpolates toward another vector. A fraction of 0 returns this vector; 1 returns the target vector.

Max

Vector3:Max(args: ...Vector3): Vector3

Returns the component-wise maximum of this vector and the supplied vectors.

Min

Vector3:Min(args: ...Vector3): Vector3

Returns the component-wise minimum of this vector and the supplied vectors.

Sign

Vector3:Sign(): Vector3

Returns the sign of each component as -1, 0, or 1.

Operators

__add · __div · __eq · __mul · __sub · __tostring · __type · __unm

Example

Luau
local vector = Vector3.new(1, 2, 3)
print(vector.Magnitude)

Used by

49 classes declare a member of this type. See Classes for the class reference.

CFrame · Vector2 · Region3 · Ray