Skip to main content
Version: latest - a1.7.0 βš–οΈ

Vector

A vector composed of components (X, Y, Z) with floating point precision.

Tip

This structure is Open Sourced at https://github.com/nanos-world/nanos-world-lua-lib. Feel free to push merge 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.

πŸ‘Œ Usage​

local new_vector = Vector(1452.5, 512, 943.1)

🎚 Properties​

TypeNameDescription
numberXX Coordinate
numberYY Coordinate
numberZZ Coordinate

⏩ Functions​

tip

Note: This structure supports +, -, *, /, ^, ==, and tostring operations.

ReturnsNameDescription
booleanEquals(other, tolerance)Check against another vector for equality, within specified error limits
numberDistance(other)Distance between two points
numberDistanceSquared(other)Squared distance between two points
VectorGetUnsafeNormal()Calculates normalized version of vector without checking for zero length
VectorGetSafeNormal()Gets a normalized copy of the vector, checking it is safe to do so based on the length
booleanIsNearlyZero(tolerance)Checks whether vector is near to zero within a specified tolerance
booleanIsZero()Checks whether all components of the vector are exactly zero
booleanNormalize()Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not
numberSize()Get the length (magnitude) of this vector
numberSizeSquared()Get the squared length of this vector
RotatorRotation()Returns the orientation corresponding to the direction in which the vector points