Vector3

Show Deprecated

The Vector3 data type represents a vector in 3D space, typically usually used as a point in 3D space or the dimensions of a rectangular prism. Vector3 supports basic component-based arithmetic operations (sum, difference, product, and quotient) and these operations can be applied on the left or right hand side to either another Vector3 or a number. It also features methods for common vector operations, such as Cross() and Dot().

Some example usages of Vector3 are the Position, Rotation, and Size of parts, for example:


local part = workspace.Part
part.Position = part.Position + Vector3.new(5, 2, 10) -- Move part by (5, 2, 10)

Vector3 is also commonly used when constructing more complex 3D data types such as CFrame. Many of these data types' methods will use a Vector3 within their parameters, such as CFrame:PointToObjectSpace().

Math Operations

The following math operations are valid for the Vector3 data type:

OperationDescription
Vector3 + Vector3Produces a Vector3 with each component of the second added to the corresponding component of the first.
Vector3 - Vector3Produces a Vector3 with each component of the second subtracted from the corresponding component of the first.
Vector3 * Vector3Produces a Vector3 with each component of the second multiplied by the corresponding component of the first.
Vector3 / Vector3Produces a Vector3 with each component of the first divided by the corresponding component of the second.
Vector3 * numberProduces a Vector3 with each component multiplied by the number.
Vector3 / numberProduces a Vector3 with each component divided by the number.

Summary

Constructors

new(x: number, y: number, z: number)  

FromNormalId(normal: NormalId)  

FromAxis(axis: Axis)  

Properties

A Vector3 with a magnitude of zero.

A Vector3 with a value of 1 on every axis.

A Vector3 with a value of 1 on the X axis.

A Vector3 with a value of 1 on the Y axis.

A Vector3 with a value of 1 on the Z axis.

The x-coordinate of the Vector3.

The y-coordinate of the Vector3.

The z-coordinate of the Vector3.

The length of the Vector3.

A normalized copy of the Vector3 - one that has the same direction as the original but a magnitude of 1.

Methods

Cross(other: Vector3): Vector3  

Returns the cross product of the two vectors.

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

Returns the angle in radians between the two vectors. If an axis is provided, it determines the sign of the angle.

Dot(other: Vector3): number  

Returns a scalar dot product of the two vectors.

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

Returns true if the X, Y, and Z components of the other Vector3 are within epsilon units of each corresponding component of this Vector3.

Lerp(goal: Vector3, alpha: number): Vector3  

Returns a Vector3 linearly interpolated between this Vector3 and the given goal by the given alpha.

Max(vector: Vector3): Vector3  

Returns a Vector3 with each component as the highest among the respective components of both provided Vector3 objects.

Min(vector: Vector3): Vector3  

Returns a Vector3 with each component as the lowest among the respective components of both provided Vector3 objects.

Math Operations

+  

-  

*  

/  

*  

/  

Constructors

new

Parameters

Default Value: 0
Default Value: 0
Default Value: 0

FromNormalId

Parameters

normal: NormalId

FromAxis

Parameters

axis: Axis

Properties

A Vector3 with a magnitude of zero.

This API member is a constant, and must be accessed through the Vector3 global as opposed to an individual Vector3 object.


print(Vector3.zero) --> 0, 0, 0

A Vector3 with a value of 1 on every axis.

This API member is a constant, and must be accessed through the Vector3 global as opposed to an individual Vector3 object.


print(Vector3.one) --> 1, 1, 1

xAxis

A Vector3 with a value of 1 on the X axis.

This API member is a constant, and must be accessed through the Vector3 global as opposed to an individual Vector3 object.


print(Vector3.xAxis) --> 1, 0, 0

yAxis

A Vector3 with a value of 1 on the Y axis.

This API member is a constant, and must be accessed through the Vector3 global as opposed to an individual Vector3 object.


print(Vector3.yAxis) --> 0, 1, 0

zAxis

A Vector3 with a value of 1 on the Z axis.

This API member is a constant, and must be accessed through the Vector3 global as opposed to an individual Vector3 object.


print(Vector3.zAxis) --> 0, 0, 1

The x-coordinate of the Vector3.

The y-coordinate of the Vector3.

The z-coordinate of the Vector3.

Magnitude

The length of the Vector3.

A normalized copy of the Vector3 - one that has the same direction as the original but a magnitude of 1.

Methods

Cross

Returns the cross product of the two vectors.

Parameters

other: Vector3

Returns

Angle

Returns the angle in radians between the two vectors. If an axis is provided, it determines the sign of the angle.

Parameters

other: Vector3
axis: Vector3
Default Value: nil

Returns

Returns a scalar dot product of the two vectors.

Parameters

other: Vector3

Returns

FuzzyEq

Returns true if the X, Y, and Z components of the other Vector3 are within epsilon units of each corresponding component of this Vector3.

Parameters

other: Vector3
epsilon: number
Default Value: 0.00001 aka 1e-5

Returns

Returns a Vector3 linearly interpolated between this Vector3 and the given goal Vector3 by the fraction alpha.

Note: the alpha value is not limited to the range [0, 1].

Parameters

goal: Vector3
alpha: number

Returns

Returns a Vector3 with each component as the highest among the respective components of both provided Vector3 objects.


local a = Vector3.new(1, 2, 1)
local b = Vector3.new(2, 1, 2)
print(a:Max(b)) --> Vector3.new(2, 2, 2)

Parameters

vector: Vector3

Returns

Returns a Vector3 with each component as the lowest among the respective components of both provided Vector3 objects.


local a = Vector3.new(1, 2, 1)
local b = Vector3.new(2, 1, 2)
print(a:Min(b)) --> Vector3.new(1, 1, 1)

Parameters

vector: Vector3

Returns

Math Operations