Vector3
Overview
Vector3 is a data type used to express vector in a three-dimensional space using X, Y, and Z axes. It is used to handle a variety of 3D data such as position, direction, speed, and strength. It is also one of the key elements used by many systems to calculate coordinates and vector within a space or simulating 3D physics.
Constructors
new
Creates and returns a new vector using the passed X, Y, and Z values.
Parameters
number x
The value of X coordinate.
number y
The value of Y coordinate.
number z
The value of Z coordinate.
Return
Vector3
The created Vector3.
Code Samples
local Vector = Vector3.new(1, 2, 3)
print(Vector)Properties
Magnitude
number
The value representing the size of a Vector3.
Code Samples
one
Vector3
A vector of which axis values are ones (1, 1, 1).
Code Samples
Unit
Vector3
A Vector3 of which size is removed and length is 1 while maintaining the original direction.
Code Samples
X
number
The value of X coordinate.
Code Samples
xAxis
Vector3
A Vector3 set to have the value of 1 for X axis and 0 for other axes (1, 0, 0).
Code Samples
Y
number
The value of Y coordinate.
Code Samples
yAxis
Vector3
A Vector3 set to have the value of 1 for Y axis and 0 for other axes (0, 1, 0).
Code Samples
Z
number
The value of Z coordinate.
Code Samples
zAxis
Vector3
A Vector3 set to have the value of 1 for Z axis and 0 for other axes (0, 0, 1).
Code Samples
zero
Vector3
A vector of which axis values are zeroes (0, 0, 0).
Code Samples
Methods
Abs
Makes each coordinate of a vector positive, even if some of them were negative, and returns a new vector.
Parameters
Return
Vector3
The created Vector3.
Code Samples
Angle
Calculates the angle between two vectors in radian and returns it. If there is a reference axis, the direction of the angle is also considered in the return value.
Parameters
Value InOtherValue
The Vector3 to calculate its angle.
Value AxisValue
The Vector3 to be used as a reference axis to determine the direction of an angle. If no axis is provided, only the absolute angle between two vectors is calculated.
Return
number
Returns the angle between two vectors in radian.
Code Samples
Ceil
Rounds up each coordinate of the vectors and returns a new vector.
Parameters
Return
Vector3
The created Vector3.
Code Samples
ClampMagnitude
Returns a new vector of which length is restricted not to exceed maxLength.
Parameters
number MaxLength
The maximum value used to restrict vector length.
Return
Vector3
The created Vector3.
Code Samples
Cross
Returns the cross product between two vectors as a new vector.
Parameters
Value InOtherValue
The Vector3 to compute the cross product with.
Return
Vector3
The created Vector3.
Code Samples
Distance
Returns the distance between two vectors.
Parameters
Vector3 OtherValue
The Vector3 to calculate distance.
Return
number
Returns the linear distance between two vectors in a numeric value.
Code Samples
Dot
Returns the dot value between two vectors as a scalar.
Parameters
Value InOtherValue
The Vector3 to calculate its dot product.
Return
number
Returns the dot product between two vectors as a scalar.
Code Samples
Floor
Rounds down each coordinate of the exiting vectors and returns a new vector.
Parameters
Return
Vector3
The created Vector3.
Code Samples
FuzzyEq
Compares the squared size of both vectors and returns true if both values are within the epsilon range calculated according to vector size. In this case, both vectors are treated as the same vector.
Parameters
Value InOtherValue
The Vector3 to compare.
number Epsilon
A value indicates tolerance. This value is applied in proportion to vector size. It is used to determine whether the difference of two squared vectors is within this range.
Return
boolean
Returns true if the difference of two squared vectors is within the epsilon tolerance according to vector size.
Code Samples
Lerp
Calculates the linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.
Parameters
Vector3 GoalValue
The target Vector3 to be interpolated.
number Alpha
A value indicating interpolation ratio.
Return
Vector3
The created Vector3.
Code Samples
Max
Compares the X, Y, and Z value of two vectors, selects the higher value for each axis, and returns a new vector with the selected values.
Parameters
Vector3 OtherValue
The other Vector3 to compare.
Return
Vector3
The created Vector3.
Code Samples
Min
Compares the X, Y, and Z value of two vectors, selects the lower value for each axis, and returns a new vector with the selected values.
Parameters
Vector3 OtherValue
The other Vector3 to compare.
Return
Vector3
The created Vector3.
Code Samples
MoveTowards
Returns a new vector, which is moved from the current vector toward the target vector in the distance of maxDelta.
Parameters
Vector3 TargetValue
The Vector3 to be the movement target.
number MaxDelta
The maximum distance movable in a single calculation.
Return
Vector3
The created Vector3.
Code Samples
Reflect
Returns a new vector, which is reflected by a given normal vector.
Parameters
Vector3 NormalValue
The normal vector (Vector3) to be the reference point of reflection.
Return
Vector3
The created Vector3.
Code Samples
Rotate
Returns a new vector, which is rotated by radians along the provided axis.
Parameters
Vector3 AxisValue
The Vector3 to be the rotation axis.
number Radians
A value specifying the angle by which a vector is rotated, measured in radian.
Return
Vector3
The created Vector3.
Code Samples
Sign
Converts the each coordinate of an existing vector and returns the result as a new vector. Any negative number is converted to -1; any positive value is converted to 1; and 0 is not converted.
Parameters
Return
Vector3
The created Vector3.
Code Samples
Slerp
Calculates the spherical linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.
While Lerp interpolates along a linear path, Slerp interpolates along a curve on a unit sphere, making its rotation axis movement smoother and more constant.
Parameters
Vector3 GoalValue
The target Vector3 to be interpolated.
number Alpha
A value indicating interpolation ratio.
Return
Vector3
The created Vector3.
Code Samples
Events
See also
Coordinate SystemLast updated