⚙️vector
This type is a common 3D vector (x, y, z).
x
Type: float
X coordinate.
y
Type: float
Y coordinate.
z
Type: float
Z coordinate.
__call
Constructs a vector.
Arguments
1. Default vector (0, 0, 0).
None.
2. Single value.
Name
Type
Description
value
float
X and Y coordinates.
3. XYZ values.
Name
Type
Description
x
float
X coordinate.
y
float
Y coordinate.
z
float
Z coordinate.
Returns
Type
Description
vector
Vector.
Example
local vec = vector(5, 25, 12);
is_zero
Returns true
if this vector is within tolerance range.
Arguments
Name
Type
Description
tolerance
float
Max allowed tolerance. Defaults to 0.01
.
Returns
Type
Description
bool
true
if ranges between -tolerance
and tolerance
.
Example
local vec = vector(0, 0.1, 0.5);
print(tostring(vec:is_zero(1))); -- will print 'true', because every value fits in the range of -1 and 1
dist
Returns distance to another vector.
Arguments
Name
Type
Description
other
vector
Vector to calculate distance against.
Returns
Type
Description
float
Distance to other vector.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist(vec2)));
dist_sqr
Returns squared distance to another vector.
Arguments
Name
Type
Description
other
vector
Vector to calculate distance against.
Returns
Type
Description
float
Squared distance to other vector.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_sqr(vec2)));
dist_2d
Returns 2D (only x
and y
values) distance to another vector.
Arguments
Name
Type
Description
other
vector
Vector to calculate distance against.
Returns
Type
Description
float
Distance to other vector.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_2d(vec2)));
dist_2d_sqr
Returns squared 2D (only x
and y
values) distance to another vector.
Arguments
Name
Type
Description
other
vector
Vector to calculate distance against.
Returns
Type
Description
float
Squared distance to other vector.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
print(tostring(vec1:dist_2d_sqr(vec2)));
cross
Returns a cross product to another vector.
Arguments
Name
Type
Description
other
vector
Vector to calculate cross product against.
Returns
Type
Description
vector
Cross product.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
local cross = vec1:cross(vec2);
is_valid
Returns true
if all values in this vector are finite.
Arguments
None.
Returns
Type
Description
bool
true
if values are finite.
Example
local vec = vector(5, 1, 6);
if vec:is_valid() then
-- ...
end
length
Returns length of this vector.
Arguments
None.
Returns
Type
Description
float
Length of this vector.
Example
local vec = vector(5, 1, 6);
local length = vec:length();
length_sqr
Returns squared length of this vector.
Arguments
None.
Returns
Type
Description
float
Length of this vector.
Example
local vec = vector(5, 1, 6);
local length = vec:length_sqr();
length_2d
Returns 2D length of this vector.
Arguments
None.
Returns
Type
Description
float
Length of this vector.
Example
local vec = vector(5, 1, 6);
local length = vec:length_2d();
length_2d_sqr
Returns squared 2D length of this vector.
Arguments
None.
Returns
Type
Description
float
Length of this vector.
Example
local vec = vector(5, 1, 6);
local length = vec:length_2d_sqr();
dot
Returns dot product of 2 vectors.
Arguments
Name
Type
Description
other
vector
Vector to calculate dot product against.
Returns
Type
Description
float
Dot product.
Example
local vec1 = vector(0, 0, 0);
local vec2 = vector(1, 1, 5);
local dot = vec1:dot(vec2);
Last updated