Passer au contenu principal
Version: latest - a1.156.0 ⚖️

📐 Vector

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


info

Les vecteurs sont compressés en interne et automatiquement, ce qui réduit leur taille dans le réseau jusqu'à 90 %. Des détails intéressants :

  • Les paramètres des vecteurs dans les méthodes des classes sont généralement compressés avec une précision de 1 décimale (avec quelques exceptions où nous avons besoin de plus de précision).
  • Les vecteurs transmis dans les événements distants sont compressés avec une précision de 2 décimales. If you need more precision, we recommend passing them as raw number instead.

🎒 Exemples​

local new_vector = Vector(1452.5, 512, 943.1)

🛠 Constructors​

Default Constructor​

No description provided

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

Parameters

TypeNameDefaultDescription
floatX0Coordonnée X
floatYXCoordonnée Y
floatZXCoordonnée Z

🧽 Properties​

TypeNameDescription
floatXCoordonnée X
floatYCoordonnée Y
floatZCoordonnée Z

🦠 Fonctions​

info

This structure supports +, -, *, /, ^, ==, unary - (negation) and tostring operations.

ReturnsNameDescription
booleanEqualsVérifie l'égalité avec un autre vecteur, dans les limites d'erreur spécifiées
floatDistanceDistance entre deux points
floatDistanceSquaredDistance au carré entre deux points
VectorGetUnsafeNormalCalcule la version normalisée du vecteur sans vérifier si la longueur est nulle
VectorGetSafeNormalObtient une copie normalisée du vecteur, en vérifiant qu'il est possible de le faire en fonction de la longueur
booleanIsNearEfficiently checks whether vector is near to another vector within a specified radius
booleanIsNearlyZeroVérifie si le vecteur est proche de zéro dans une tolérance spécifiée
booleanIsZeroVérifie si tous les composants du vecteur sont exactement égales à zéro
booleanNormalizeNormalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not
floatSizeObtient la longueur (magnitude) de ce vecteur
floatSizeSquaredObtenir la longueur au carré de ce vecteur
RotatorToOrientationRotatorReturn the Rotator orientation corresponding to the direction in which the vector points
QuatToOrientationQuatReturn the Quaternion orientation corresponding to the direction in which the vector points
floatDotDot product of two vectors
VectorCrossCross product of two vectors

Optimal

Equals​

Check if the vector is equal to another vector, within specified error limits
local ret = my_vector:Equals(other, tolerance?)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to compare to
floattolerance?0.000001
The error limits

Returns

TypeDescription
booleanAre the vectors equal or not

Optimal

Distance​

Returns the distance of 2 vectors
local ret = my_vector:Distance(other)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to get the distance to

Returns

TypeDescription
floatThe distance between the vectors

Optimal

DistanceSquared​

Return the squared distance of 2 vectors
local ret = my_vector:DistanceSquared(other)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to get the squared distance to

Returns

TypeDescription
floatThe squared distance between the vectors

Optimal

GetUnsafeNormal​

Returns the normalized version of vector without checking for zero length
local ret = my_vector:GetUnsafeNormal()

Returns

TypeDescription
VectorThe unsafe normal

Optimal

GetSafeNormal​

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

TypeParameterDefaultDescription
floattolerance?0.000001
Minimum squared size to consider it non-zero

Returns

TypeDescription
VectorThe safe normal

Optimal

IsNear​

Efficiently checks whether vector is near to another vector within a specified radius
local ret = my_vector:IsNear(other, radius)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to compare to
floatradius Required parameter The radius to check

Returns

TypeDescription
booleanIf the vector is near to the other vector

Optimal

IsNearlyZero​

Vérifie si le vecteur est proche de zéro dans une tolérance spécifiée
local ret = my_vector:IsNearlyZero(tolerance?)

Parameters

TypeParameterDefaultDescription
floattolerance?0.000001
The error limits

Returns

TypeDescription
booleanIf the bool is near to zero

Optimal

IsZero​

Vérifie si tous les composants du vecteur sont exactement égales à zéro
local ret = my_vector:IsZero()

Returns

TypeDescription
booleanIf all components of the vector are exactly zero

Optimal

Normalize​

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

TypeParameterDefaultDescription
floattolerance?0.000001
Minimum squared size to consider it non-zero

Returns

TypeDescription
booleanIf the vector has been modified

Optimal

Size​

Obtient la longueur (magnitude) de ce vecteur
local ret = my_vector:Size()

Returns

TypeDescription
floatThe length of the vector

Optimal

SizeSquared​

Obtenir la longueur au carré de ce vecteur
local ret = my_vector:SizeSquared()

Returns

TypeDescription
floatThe squared length of the vector

Optimal

ToOrientationRotator​

Return the Rotator orientation corresponding to the direction in which the vector points
local ret = my_vector:ToOrientationRotator()

Returns

TypeDescription
RotatorThe orientation of the vector

Optimal

ToOrientationQuat​

Return the Quaternion orientation corresponding to the direction in which the vector points
local ret = my_vector:ToOrientationQuat()

Returns

TypeDescription
QuatThe orientation of the vector

Optimal

Dot​

Returns the dot product between this vector and another vector
local ret = my_vector:Dot(other)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to dot with

Returns

TypeDescription
floatthe dot product

Optimal

Cross​

Returns the cross product between this vector and another vector
local ret = my_vector:Cross(other)

Parameters

TypeParameterDefaultDescription
Vectorother Required parameter The vector to cross with

Returns

TypeDescription
Vectorthe cross product vector