-
Notifications
You must be signed in to change notification settings - Fork 0
Extended: Vector
How to get this userdata:
Vector()The Vector userdata now support calculating:
local vector1 = Vector(1, 2, 3)
local vector2 = Vector(4, 5, 6)
print(vector1 + vector2) -- Output: "5.000000 7.000000 9.000000"
print(vector1 / vector2) -- Output: "0.250000 0.400000 0.500000"
print(vector1 * vector2) -- Output: "4.000000 10.000000 18.000000"
print(vector1 - vector2) -- Output: "-3.000000 -3.000000 -3.000000"
print(-vector1) -- Output: "-1.000000 -2.000000 -3.000000"
print(vector1 == vector2) -- Output: "false"tostring(vector)Format vector to a proper string "x y z", with maximum 6 decimal places.
vector:Add(vector)Adds the values of the argument vector to the original vector.
This function is the same as vector1 + vector2 without creating a new vector object, skipping object construction and garbage collection.
vector: vector
vector:Angle()Returns an angle representing the normal of the vector.
Return: angle
vector:Cross(vector)Calculates the cross product of this vector and the passed one.
Return: vector
vector: vector
vector:Distance(vector)Returns the Euclidean distance between the vector and the other vector.
Return: number
vector: vector
vector:DistToSqr(vector)Returns the squared distance of 2 vectors.
This is quicker to call than vector:Distance() as DistToSqr does not need to calculate the square root, which is an expensive process.
Return: number
vector: vector
vector:Div(divisor)Divides all values of the original vector by a scalar.
This functions the same as vector1 / num without creating a new vector object, skipping object construction and garbage collection.
divisor: number
vector:Dot(vector)Returns the dot product of this vector and the passed one.
Return: number
vector: vector
vector:IsZero()Checks whenever all fields of the vector are 0.
Return: true or false
vector:Length()Returns the Euclidean length of the vector.
Return: number
vector:Length2D()Returns the length of the vector in two dimensions, without the Z axis.
Return: number
vector:Length2DSqr()Returns the squared length of the vectors x and y value.
Return: number
vector:LengthSqr()Returns the squared length of the vector.
Return: number
vector:Mul(multiplier)Multiplies a scalar to all the values of the orignal vector.
This functions the same as vector1 * num without creating a new vector object, skipping object construction and garbage collection.
multiplier: number
vector:Sub(vector)Subtracts the values of the argument vector to the orignal vector.
This functions the same as vector1 - vector2 without creating a new vector object, skipping object construction and garbage collection.
vector: vector