📐 Vector
A Vector composed of components (X, Y, Z) with floating point precision. Used mainly for entity position.
👐Open Source
This library implementation is Open Sourced on GitHub!
🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
info
Vectors are internally and automatically compressed, which reduces it's size in the network up to 90%. Some cool details:
- Vectors parameters in Classes Methods are usually compressed with precision of 1 decimal place (with some exceptions which we need more precision).
- Vectors passed in Remote Events are compressed with precision of 2 decimal places. If you need more precision, we recommend passing them as raw number instead.
🎒 Examples
local new_vector = Vector(1452.5, 512, 943.1)
🛠 Constructors
Default Constructor
No description provided
local my_vector = Vector(X?, Y?, Z?)
🧽 Properties
🦠 Functions
info
This structure supports +, -, *, /, ^, ==, and tostring operations.
| Returns | Name | Description | |
|---|---|---|---|
| boolean | Equals | Check against another vector for equality, within specified error limits | |
| number | Distance | Distance between two points | |
| number | DistanceSquared | Squared distance between two points | |
| Vector | GetUnsafeNormal | Calculates normalized version of vector without checking for zero length | |
| Vector | GetSafeNormal | Gets a normalized copy of the vector, checking it is safe to do so based on the length | |
| boolean | IsNear | Efficiently checks whether vector is near to another vector within a specified radius | |
| boolean | IsNearlyZero | Checks whether vector is near to zero within a specified tolerance | |
| boolean | IsZero | Checks whether all components of the vector are exactly zero | |
| boolean | Normalize | Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not | |
| number | Size | Get the length (magnitude) of this vector | |
| number | SizeSquared | Get the squared length of this vector | |
| Rotator | ToOrientationRotator | Return the Rotator orientation corresponding to the direction in which the vector points | |
| Quat | ToOrientationQuat | Return the Quaternion orientation corresponding to the direction in which the vector points | |
| number | Dot | Dot product of two vectors | |
| Vector | Cross | Cross product of two vectors |
Equals
Check if the vector is equal to another vector, within specified error limits
local ret = my_vector:Equals(other, tolerance?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to compare to |
| number | tolerance? | 0.000001 | The error limits |
Returns
| Type | Description |
|---|---|
| boolean | Are the vectors equal or not |
Distance
Returns the distance of 2 vectors
local ret = my_vector:Distance(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to get the distance to |
Returns
| Type | Description |
|---|---|
| number | The distance betweem the vectors |
DistanceSquared
Return the squared distance of 2 vectors
local ret = my_vector:DistanceSquared(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to get the squared distance to |
Returns
| Type | Description |
|---|---|
| number | The squared distance betweem the vectors |
GetUnsafeNormal
Returns the normalized version of vector without checking for zero length
local ret = my_vector:GetUnsafeNormal()
Returns
| Type | Description |
|---|---|
| Vector | The unsafe normal |
GetSafeNormal
Returns a normalized copy of the vector, checking it is safe to do so based on the length
local ret = my_vector:GetSafeNormal()
Returns
| Type | Description |
|---|---|
| Vector | The safe normal |
IsNear
Efficiently checks whether vector is near to another vector within a specified radius
local ret = my_vector:IsNear(other, radius)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to compare to |
| number | radius | Required parameter | The radius to check |
Returns
| Type | Description |
|---|---|
| boolean | If the vector is near to the other vector |
IsNearlyZero
Checks whether vector is near to zero within a specified tolerance
local ret = my_vector:IsNearlyZero(tolerance?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | tolerance? | 0.000001 | The error limits |
Returns
| Type | Description |
|---|---|
| boolean | If the bool is near to zero |
IsZero
Checks whether all components of the vector are exactly zero
local ret = my_vector:IsZero()
Returns
| Type | Description |
|---|---|
| boolean | If all components of the vector are exactly zero |
Normalize
Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not
local ret = my_vector:Normalize()
Returns
| Type | Description |
|---|---|
| boolean | If the vector has been modified |
Size
Get the length (magnitude) of this vector
local ret = my_vector:Size()
Returns
| Type | Description |
|---|---|
| number | The lenght of the vector |
SizeSquared
Get the squared length of this vector
local ret = my_vector:SizeSquared()
Returns
| Type | Description |
|---|---|
| number | The squared length of the vector |
ToOrientationRotator
Return the Rotator orientation corresponding to the direction in which the vector points
local ret = my_vector:ToOrientationRotator()
Returns
| Type | Description |
|---|---|
| Rotator | The orientation of the vector |
ToOrientationQuat
Return the Quaternion orientation corresponding to the direction in which the vector points
local ret = my_vector:ToOrientationQuat()
Returns
| Type | Description |
|---|---|
| Quat | The orientation of the vector |
Dot
Returns the dot product between this vector and another vector
local ret = my_vector:Dot(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to dot with |
Returns
| Type | Description |
|---|---|
| number | the dot product |
Cross
Returns the cross product between this vector and another vector
local ret = my_vector:Cross(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | other | Required parameter | The vector to cross with |
Returns
| Type | Description |
|---|---|
| Vector | the cross product vector |