๐ Vector
A Vector composed of components (X, Y, Z) with floating point precision. Used mainly for entity position
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โ
๐งฝ Propertiesโ
๐ฆ Functionsโ
This structure supports +, -, *, /, ^, ==, unary - (negation) and tostring operations.
Equals: boolean | Check against another vector for equality, within specified error limits | |
Distance: float | Distance between two points | |
DistanceSquared: float | Squared distance between two points | |
GetUnsafeNormal: Vector | Calculates normalized version of vector without checking for zero length | |
GetSafeNormal: Vector | Gets a normalized copy of the vector, checking it is safe to do so based on the length | |
IsNear: boolean | Efficiently checks whether vector is near to another vector within a specified radius | |
IsNearlyZero: boolean | Checks whether vector is near to zero within a specified tolerance | |
IsZero: boolean | Checks whether all components of the vector are exactly zero | |
Normalize: boolean | Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not | |
Size: float | Get the length (magnitude) of this vector | |
SizeSquared: float | Get the squared length of this vector | |
ToOrientationRotator: Rotator | Return the Rotator orientation corresponding to the direction in which the vector points | |
ToOrientationQuat: Quat | Return the Quaternion orientation corresponding to the direction in which the vector points | |
Dot: float | Dot product of two vectors | |
Cross: Vector | Cross product of two vectors |
EqualsOptimalโ
Check against another vector for equality, within specified error limits
Check if the vector is equal to another vector, within specified error limits
local ret = my_vector:Equals(other, tolerance?)
Parameters
| Name | Type | Description |
|---|---|---|
other | Vector | The vector to compare to |
tolerance? | float | The error limits Default 0.000001 |
Returns
| Type | Description |
|---|---|
| boolean | Are the vectors equal or not |
DistanceOptimalโ
Distance between two points
Returns the distance of 2 vectors
local ret = my_vector:Distance(other)
Parameters
| Name | Type | Description |
|---|---|---|
other | Vector | The vector to get the distance to |
Returns
| Type | Description |
|---|---|
| float | The distance between the vectors |
DistanceSquaredOptimalโ
Squared distance between two points
Return the squared distance of 2 vectors
local ret = my_vector:DistanceSquared(other)
Parameters
| Name | Type | Description |
|---|---|---|
other | Vector | The vector to get the squared distance to |
Returns
| Type | Description |
|---|---|
| float | The squared distance between the vectors |
GetUnsafeNormalOptimalโ
Calculates normalized version of vector without checking for zero length
Returns the normalized version of vector without checking for zero length
local ret = my_vector:GetUnsafeNormal()
Returns
| Type | Description |
|---|---|
| Vector | The unsafe normal |
GetSafeNormalOptimalโ
Gets a normalized copy of the vector, checking it is safe to do so based on the length
Returns a normalized copy of the vector, checking it is safe to do so based on the length
local ret = my_vector:GetSafeNormal(tolerance?)
Parameters
| Name | Type | Description |
|---|---|---|
tolerance? | float | Minimum squared size to consider it non-zero Default 0.000001 |
Returns
| Type | Description |
|---|---|
| Vector | The safe normal |
IsNearOptimalโ
Efficiently checks whether vector is near to another vector within a specified radius
local ret = my_vector:IsNear(other, radius)
Returns
| Type | Description |
|---|---|
| boolean | If the vector is near to the other vector |
IsNearlyZeroOptimalโ
Checks whether vector is near to zero within a specified tolerance
local ret = my_vector:IsNearlyZero(tolerance?)
Parameters
| Name | Type | Description |
|---|---|---|
tolerance? | float | The error limits Default 0.000001 |
Returns
| Type | Description |
|---|---|
| boolean | If the bool is near to zero |
IsZeroOptimalโ
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 |
NormalizeOptimalโ
Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not
local ret = my_vector:Normalize(tolerance?)
Parameters
| Name | Type | Description |
|---|---|---|
tolerance? | float | Minimum squared size to consider it non-zero Default 0.000001 |
Returns
| Type | Description |
|---|---|
| boolean | If the vector has been modified |
SizeOptimalโ
Get the length (magnitude) of this vector
local ret = my_vector:Size()
Returns
| Type | Description |
|---|---|
| float | The length of the vector |
SizeSquaredOptimalโ
Get the squared length of this vector
local ret = my_vector:SizeSquared()
Returns
| Type | Description |
|---|---|
| float | The squared length of the vector |
ToOrientationRotatorOptimalโ
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 |
ToOrientationQuatOptimalโ
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 |
