Vector3

Show Deprecated

The Vector3 data type represents a vector in 3D space, typically 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().

Alternatively to Vector3, consider using the methods and properties of the vector library.

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


local Workspace = game:GetService("Workspace")
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().

Summary

Constructors

Properties

Methods

  • Returns a new vector from the absolute values of the original's components.

  • Returns a new vector from the ceiling of the original's components.

  • Returns a new vector from the floor of the original's components.

  • Returns a new vector from the sign (-1, 0, or 1) of the original's components.

  • Returns the cross product of the two vectors.

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

    Returns the angle in radians between the two vectors. If you provide an axis, 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):bool

    Returns true if the difference between the squared magnitude of the two vectors is within epsilon. epsilon is scaled relative to the magnitude, rather than an absolute epsilon.

  • 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

  • Produces a Vector3 by adding each component of the first vector to the corresponding component of the second.

  • Produces a Vector3 by subtracting each component of the second vector from the corresponding component of the first.

  • Produces a Vector3 by multiplying each component of the first vector by the corresponding component of the second.

  • Produces a Vector3 by dividing each component of the first vector by the corresponding component of the second.

  • Produces a Vector3 by floor dividing each component of the first vector by the corresponding component of the second.

  • Produces a Vector3 by multiplying each component of the provided vector by the number.

  • Produces a Vector3 by dividing each component of the provided vector by the number.

  • Produces a Vector3 by floor dividing each component of the provided vector by the number.

Constructors

new

Returns a new Vector3 using the given x, y, and z components.

Parameters

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

FromNormalId

Returns a new Vector3 in the given direction.

Parameters

FromAxis

Returns a new Vector3 for the given axis.

Parameters

axis: Enum.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

Returns a new vector from the absolute values of the original's components. For example, a vector of (-2, 4, -6) returns a vector of (2, 4, 6).

Returns

Returns a new vector from the ceiling of the original's components. For example, a vector of (-2.6, 5.1, 8.8) returns a vector of (-2, 6, 9).

Returns

Floor

Returns a new vector from the floor of the original's components. For example, a vector of (-2.6, 5.1, 8.8) returns a vector of (-3, 5, 8).

Returns

Returns a new vector from the sign (-1, 0, or 1) of the original's components. For example, a vector of (-2.6, 5.1, 0) returns a vector of (-1, 1, 0).

Returns

Cross

Returns the cross product of the two vectors.

Parameters

other: Vector3

Returns

Angle

Returns the angle in radians between the two vectors. If you provide an axis, 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 difference between the squared magnitude of the two vectors is within epsilon. epsilon is scaled relative to the magnitude, rather than an absolute epsilon.

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


Produces a Vector3 by adding each component of the first vector to the corresponding component of the second.


Produces a Vector3 by subtracting each component of the second vector from the corresponding component of the first.


Produces a Vector3 by multiplying each component of the first vector by the corresponding component of the second.


Produces a Vector3 by dividing each component of the first vector by the corresponding component of the second.


Produces a Vector3 by floor dividing each component of the first vector by the corresponding component of the second.


Produces a Vector3 by multiplying each component of the provided vector by the number.


Produces a Vector3 by dividing each component of the provided vector by the number.


Produces a Vector3 by floor dividing each component of the provided vector by the number.