PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Vector3

Vector3

Vector3 describes 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 operators: sum, difference, product, and quotient. These operations can be applied on the left or right hand side to either another Vector3 or a number. It also features functions for commonly used vector operations, such as cross and dot products.

Some example usages of Vector3 are the BasePart/Position|Position, BasePart/Rotation|Rotation and BasePart/Size|Size of BasePart|parts. Learning to set these properties are among the first things many developers will learn:

local part = workspace.Part
part.Position = part.Position + Vector3.new(5, 20, 100) -- Moves a part by this much

Vector3 is commonly used when constructing other more complex 3D data types, namely datatype/CFrame and datatype/Ray. Many of these data types’ functions will use a Vector3 within their parameters, such as CFrame:PointToObjectSpace or Ray:ClosestPoint. CFrame arithmetic also supports Vector3 for addition/subtraction.

See Also

  • datatype/Vector3int16, a lower precision implementation of 3D vectors used with Region3int16

Constructors

Vector3.new ( number x = 0, number y = 0, number z = 0 )

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

Vector3.FromNormalId ( Enum normal )

Constructs a new Vector3 in a particular direction.

Vector3.FromAxis ( Enum axis )

Constructs a new Vector3 for a particular axis.

Properties

number Vector3.X

The x-coordinate

number Vector3.Y

The y-coordinate

number Vector3.Z

The z-coordinate

number Vector3.Magnitude

The length of the vector

Vector3 Vector3.Unit

A normalized copy of the vector - one which has the same direction as the original but a magnitude of 1

Functions

Vector3 Vector3:Lerp ( Vector3 goal, number alpha )

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].

number Vector3:Dot ( Vector3 other )

Returns a scalar dot product of the two vectors

Vector3 Vector3:Cross ( Vector3 other )

Returns the cross product of the two vectors

bool Vector3:FuzzyEq ( Vector3 other, number epsilon = 0.00001 aka 1e-5 )

Returns true if the other Vector3 falls within the epsilon radius of this Vector3.

Math Operations

Vector3 Vector3 + Vector3

Returns a new Vector3 with each component of the second added to the corresponding component of the first.

Vector3 Vector3 - Vector3

Returns a new Vector3 with each component of the second subtracted from the corresponding component of the first.

Vector3 Vector3 * Vector3

Returns a new Vector3 with each component of the second multiplied the corresponding component of the first.

Vector3 Vector3 / Vector3

Returns a new Vector3 with each component of the first divided by the corresponding component of the second.

Vector3 Vector3 * number

Returns the Vector3 with each component multiplied by the number.

Vector3 Vector3 / number

Returns the Vector3 with each component divided by the number.