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
The vector (1, 1, 1).
The unit vector (1, 0, 0).
The unit vector (0, 1, 0).
The unit vector (0, 0, 1).
The constant vector (0, 0, 0).
The vector length.
Returns a vector with the same direction and length 1.
The X component.
The Y component.
The Z component.
Abs(): Vector3Returns the absolute value of each component.
Angle(other: Vector3, axis: Vector3?): numberReturns the angle to another vector in radians.
Ceil(): Vector3Returns a vector with each component rounded upward.
Cross(other: Vector3): Vector3Returns the cross product, perpendicular to both input vectors.
Dot(other: Vector3): numberReturns the dot product.
Floor(): Vector3Returns a vector with each component rounded downward.
FuzzyEq(other: Vector3, epsilon: number?): booleanReturns whether the vector components are equal within the supplied tolerance.
Lerp(other: Vector3, t: number): Vector3Interpolates toward another vector.
Max(args: ...Vector3): Vector3Returns the component-wise maximum of this vector and the supplied vectors.
Min(args: ...Vector3): Vector3Returns the component-wise minimum of this vector and the supplied vectors.
Sign(): Vector3Returns the sign of each component as -1, 0, or 1.
Constructors
FromAxis
Vector3.FromAxis(axis: EnumItem): Vector3Returns the unit vector for the specified Cartesian axis.
FromNormalId
Vector3.FromNormalId(normal: EnumItem): Vector3Returns the outward unit normal for the specified Part face.
new
Vector3.new(x: number?, y: number?, z: number?): Vector3Creates a vector from X, Y, Z components. Omitted components default to 0.
one
Vector3.one: Vector3The vector (1, 1, 1).
xAxis
Vector3.xAxis: Vector3The unit vector (1, 0, 0).
yAxis
Vector3.yAxis: Vector3The unit vector (0, 1, 0).
zAxis
Vector3.zAxis: Vector3The unit vector (0, 0, 1).
zero
Vector3.zero: Vector3The constant vector (0, 0, 0).
Properties
Magnitude
Vector3.Magnitude: numberThe vector length. The magnitude of the difference between two positions is their distance.
Unit
Vector3.Unit: Vector3Returns a vector with the same direction and length 1. Check for zero magnitude before normalizing.
X
Vector3.X: numberThe X component. Read-only.
Y
Vector3.Y: numberThe Y component. Read-only.
Z
Vector3.Z: numberThe Z component. Read-only.
Methods
Abs
Vector3:Abs(): Vector3Returns the absolute value of each component.
Angle
Vector3:Angle(other: Vector3, axis: Vector3?): numberReturns the angle to another vector in radians. An optional axis determines the sign.
Ceil
Vector3:Ceil(): Vector3Returns a vector with each component rounded upward.
Cross
Vector3:Cross(other: Vector3): Vector3Returns the cross product, perpendicular to both input vectors.
Dot
Vector3:Dot(other: Vector3): numberReturns 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(): Vector3Returns a vector with each component rounded downward.
FuzzyEq
Vector3:FuzzyEq(other: Vector3, epsilon: number?): booleanReturns whether the vector components are equal within the supplied tolerance.
Lerp
Vector3:Lerp(other: Vector3, t: number): Vector3Interpolates toward another vector. A fraction of 0 returns this vector; 1 returns the target vector.
Max
Vector3:Max(args: ...Vector3): Vector3Returns the component-wise maximum of this vector and the supplied vectors.
Min
Vector3:Min(args: ...Vector3): Vector3Returns the component-wise minimum of this vector and the supplied vectors.
Sign
Vector3:Sign(): Vector3Returns the sign of each component as -1, 0, or 1.
Operators
__add · __div · __eq · __mul · __sub · __tostring · __type · __unm
Example
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.