Vector3¶
Represents a 3D value with a direction and magnitude.
Description¶
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 part = Instance.new("Part")
part.Position = part.Position + Vector3.new(5, 2, 10) -- Move part by (5, 2, 10)
print(part.Position) --> 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().
Constructors¶
new Supported Returns a new Vector3 from the given x, y, and z components.
FromNormalId Supported Returns a new Vector3 in the given direction.
Returns a new Vector3 in the given direction.
Returns a unit Vector3 pointing in the direction of the given
NormalId. For example, NormalId.Top returns (0, 1, 0) and
NormalId.Front returns (0, 0, -1).
FromAxis Supported Returns a new Vector3 for the given axis.
Constants¶
zero Not yet A Vector3 with a magnitude of 0.
one Not yet A Vector3 with a value of 1 on every axis.
xAxis Not yet A Vector3 with a value of 1 on the X axis.
yAxis Not yet A Vector3 with a value of 1 on the Y axis.
zAxis Not yet A Vector3 with a value of 1 on the Z axis.
Properties¶
zero Not yet A Vector3 with a magnitude of 0.
one Not yet A Vector3 with a value of 1 on every axis.
xAxis Not yet A Vector3 with a value of 1 on the X axis.
yAxis Not yet A Vector3 with a value of 1 on the Y axis.
zAxis Not yet A Vector3 with a value of 1 on the Z axis.
X Supported The X coordinate of the Vector3.
The X coordinate of the Vector3. In world space, this axis corresponds to the left-right (east-west) direction.
Y Supported The Y coordinate of the Vector3.
The Y coordinate of the Vector3. In world space, this axis corresponds to the up-down (vertical) direction.
Z Supported The Z coordinate of the Vector3.
The Z coordinate of the Vector3. In world space, this axis corresponds to the north-south (forward-back) direction.
Magnitude Supported The length of the Vector3.
Unit Supported A normalized copy of the Vector3 - one that has the same direction as the original but a magnitude of 1.
A normalized copy of the Vector3 - one that has the same
direction as the original but a magnitude of 1.
A normalized copy of the Vector3 — one that has the same
direction as the original but a magnitude of 1. This is useful when you
need only the direction of a vector without its length, for example to get
a movement direction regardless of speed.
If the vector has a magnitude of 0 (i.e. all components are zero), the
resulting Unit vector will have NaN components. Check
Magnitude before using Unit when the vector
may be zero-length.
Methods¶
Abs Not yet Returns a new vector from the absolute values of the original's components.
Ceil Not yet Returns a new vector from the ceiling of the original's components.
Floor Not yet Returns a new vector from the floor of the original's components.
Sign Not yet Returns a new vector from the sign (-1, 0, or 1) of the original's components.
Cross Supported Returns the cross product of the two vectors.
Returns the cross product of the two vectors.
Returns the cross product of this vector and other. The resulting vector
is perpendicular to both input vectors and has a magnitude equal to the
area of the parallelogram they span. The direction follows the right-hand
rule: if you curl the fingers of your right hand from self toward
other, your thumb points in the direction of the result.
The cross product is commonly used to find normals to surfaces, determine the axis of rotation between two directions, and test whether two vectors are parallel (cross product of parallel vectors is the zero vector).
Angle Not yet Returns the angle in radians between the two vectors. If you provide an axis, it determines the sign of the angle.
Returns the angle in radians between the two vectors. If you provide an axis, it determines the sign of the angle.
Returns the angle in radians between this vector and other. The input
vectors do not need to be unit vectors. Without an axis argument, the
returned angle is always in the range [0, math.pi] (unsigned).
If you provide an axis Vector3, the returned angle is signed:
positive when the rotation from self to other follows the right-hand
rule around axis, and negative otherwise. The signed result is in the
range [-math.pi, math.pi]. The axis is used only to determine the
sign; the plane of rotation is still defined by self and other.
Dot Supported Returns a scalar dot product of the two vectors.
Returns a scalar dot product of the two vectors.
Returns the scalar dot product of this vector and other, computed as
self.X * other.X + self.Y * other.Y + self.Z * other.Z.
The dot product is useful for determining the relationship between two
directions: it equals the product of their magnitudes multiplied by the
cosine of the angle between them. For unit vectors, a result of 1 means
they point in the same direction, 0 means they are perpendicular, and
-1 means they point in opposite directions.
FuzzyEq Not yet Returns true if the difference between the squared magnitude of the two vectors is within epsilon. epsilon is scaled re…
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.
Returns true if the two vectors are approximately equal within the
tolerance defined by epsilon. The comparison is performed per-component
using a hybrid epsilon that scales relative to the magnitude of each
component, making it suitable for both small and large values. The default
epsilon of 0.00001 (1e-5) works well for most cases.
Lerp Supported Returns a Vector3 linearly interpolated between this Vector3 and the given goal by the given alpha.
Max Not yet Returns a Vector3 with each component as the highest among the respective components of both provided Vector3 objects.
Min Not yet Returns a Vector3 with each component as the lowest among the respective components of both provided Vector3 objects.
Math operations¶
+ Check Produces a Vector3 by adding each component of the first vector to the corresponding component of the second.
Produces a Vector3 by adding each component of the first vector to the corresponding component of the second.
- Check Produces a Vector3 by subtracting each component of the second vector from the corresponding component of the first.
Produces a Vector3 by subtracting each component of the second vector from the corresponding component of the first.
* Check Produces a Vector3 by multiplying each component of the first vector by the corresponding component of the second.
Produces a Vector3 by multiplying each component of the first vector by the corresponding component of the second.
/ Check Produces a Vector3 by dividing 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.
// Check Produces a Vector3 by floor 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.
* Check Produces a Vector3 by multiplying each component of the provided vector by the number.
Produces a Vector3 by multiplying each component of the provided vector by the number.
/ Check Produces a Vector3 by dividing each component of the provided vector by the number.
Produces a Vector3 by dividing each component of the provided vector by the number.
// Check Produces a Vector3 by floor 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.
Nova binding inventory¶
| Library | Members |
|---|---|
FromAxis, FromNormalId, new |
Cross, Dot, Lerp, Magnitude, Unit, X, Y, Z, isClose, lerp, magnitude, unit, x, y, z |
Roblox reference: Vector3