# π Vector

A Vector composed of components (X, Y, Z) with floating point precision. Used mainly for entity position.

πOpen Source

This structure is Open Sourced on GitHub. Feel free to make pull requests and suggest changes!

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)`

## ποΈ Constructorβ

`local my_vector = Vector(X?, Y?, Z?)`

Type | Name | Default | Description |
---|---|---|---|

number | `X` | `0` | X Coordinate |

number | `Y` | `0` | Y Coordinate |

number | `Z` | `0` | Z Coordinate |

## π§½ Propertiesβ

Type | Name | Description |
---|---|---|

number | `X` | X Coordinate |

number | `Y` | Y Coordinate |

number | `Z` | Z Coordinate |

## π¦ 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 | `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 | `Rotation` | Returns the orientation corresponding to the direction in which the vector points |

`Equals`

β

Check if the vector is equal to another vector, within specified error limits

Returns boolean (Are the vectors equal or not)

`local ret = my_vector:Equals(other, tolerance?)`

Type | Parameter | Default | Description |
---|---|---|---|

Vector | `other` | The vector to compare to | |

number | `tolerance?` | `0.000001` | The error limits |

`Distance`

β

Returns the distance of 2 vectors

Returns number (The distance betweem the vectors)

`local ret = my_vector:Distance(other)`

Type | Parameter | Default | Description |
---|---|---|---|

Vector | `other` | The vector to get the distance to |

`DistanceSquared`

β

Return the squared distance of 2 vectors

Returns number (The squared distance betweem the vectors)

`local ret = my_vector:DistanceSquared(other)`

Type | Parameter | Default | Description |
---|---|---|---|

Vector | `other` | The vector to get the squared distance to |

`GetUnsafeNormal`

β

Returns the normalized version of vector without checking for zero length

Returns Vector (The unsafe normal)

`local ret = my_vector:GetUnsafeNormal()`

`GetSafeNormal`

β

Returns a normalized copy of the vector, checking it is safe to do so based on the length

Returns Vector (The safe normal)

`local ret = my_vector:GetSafeNormal()`

`IsNearlyZero`

β

Checks whether vector is near to zero within a specified tolerance

Returns boolean (If the bool is near to zero)

`local ret = my_vector:IsNearlyZero(tolerance?)`

Type | Parameter | Default | Description |
---|---|---|---|

number | `tolerance?` | `0.000001` | The error limits |

`IsZero`

β

Checks whether all components of the vector are exactly zero

Returns boolean (If all components of the vector are exactly zero)

`local ret = my_vector:IsZero()`

`Normalize`

β

Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not

Returns boolean (If the vector has been modified)

`local ret = my_vector:Normalize()`

`Size`

β

Get the length (magnitude) of this vector

Returns number (The lenght of the vector)

`local ret = my_vector:Size()`

`SizeSquared`

β

Get the squared length of this vector

Returns number (The squared length of the vector)

`local ret = my_vector:SizeSquared()`

`Rotation`

β

Returns the orientation corresponding to the direction in which the vector points

Returns Rotator (The orientation of the vector)

`local ret = my_vector:Rotation()`