Vector3
A data type representing a 3D coordinate or direction.
local pos = Vector3.new(10, 20, 30)
print(pos) --> 10, 20, 30
pos.X = 99 -- or x, case doesn't matter
print(pos) --> 99, 20, 30
Constructor
Vector3.new(x, y, z)
Creates a new Vector3 object.
x: (Optional) number - The X component. Defaults to 0.
y: (Optional) number - The Y component. Defaults to 0.
z: (Optional) number - The Z component. Defaults to 0.
.X
number
(Read-Only) The X component of the vector.
.Y
number
(Read-Only) The Y component of the vector.
.Z
number
(Read-Only) The Z component of the vector.
local startPosition = Vector3.new(0, 50, 0)
local direction = Vector3.new(1, 0, 1)
Properties
Property
Type
Description
Access
.X
number
The X component of the vector.
Read/Write
.Y
number
The Y component of the vector.
Read/Write
.Z
number
The Z component of the vector.
Read/Write
.Magnitude
number
The length (magnitude) of the vector.
Read-Only
.Unit
Vector3
A new Vector3 with the same direction but a magnitude of 1.
Read-Only
Methods
vector:Abs() -> Vector3 Returns a new vector with the absolute values of each component.
vector:Ceil() -> Vector3 Returns a new vector with each component rounded up to the nearest integer.
vector:Floor() -> Vector3 Returns a new vector with each component rounded down to the nearest integer.
vector:Sign() -> Vector3 Returns a new vector with the sign (-1, 0, or 1) of each component.
vector:Cross(otherVector3) -> Vector3 Returns the cross product of the two vectors.
vector:Dot(otherVector3) -> number Returns the scalar dot product of the two vectors.
vector:Lerp(goalVector3, alpha) -> Vector3 Returns a Vector3 linearly interpolated between the two vectors by alpha (0.0 to 1.0).
vector:Angle(otherVector3, [axisVector3]) -> number Returns the angle in radians between two vectors. If axis is provided, the sign of the angle is determined relative to it.
vector:FuzzyEq(otherVector3, [epsilon]) -> boolean Returns true if the two vectors are approximately equal.
vector:Max(otherVector3) -> Vector3 Returns a new Vector3 with the highest components from both vectors.
vector:Min(otherVector3) -> Vector3 Returns a new Vector3 with the lowest components from both vectors.
Last updated