🔢Math
This table extends the existing math
table that is a part of Lua.
calc_angle
Function
Calculates angles between 2 vectors.
Arguments
Returns
Angles.
Example
local ang = math.calc_angle(vec1, vec2);
angle_normalize
Function
Normalizes an angle.
Arguments
angle
float
Input angle.
Returns
float
Normalized angle.
Example
local norm = math.angle_normalize(560);
approach_angles
Function
Approaches an angle over time.
Arguments
Returns
Delta angle.
Example
local ang = math.approach_angles(from, to, 1.0 / game.global_vars.frametime);
edge_point
Function
Returns a point on the edge of a box.
Arguments
Returns
Point.
Example
local point = math.edge_point(mins, maxs, dir, 5);
lerp
Function
Linear interpolation.
Arguments
t1
float
Start value.
t2
float
End value.
progress
float
Interpolation amount.
Returns
Type
Description
float
Interpolated value.
Example
local mid = math.lerp(0, 100, 0.5);
vector_angles
Function
Calculates angles from a vector.
Arguments
Returns
Angles.
Example
local ang = math.vector_angles(fw);
world_to_screen
Function
Transforms a point in the game world onto the viewport.
Arguments
round
bool
Whether should round the output. Defaults to true
.
Returns
Point on the viewport.
Example
local point = math.world_to_screen(game_point);
clamp
Function
Clamps a value between min and max.
Arguments
n
float
Value.
lower
float
Lowest value.
upper
float
Highest value.
Returns
float
Clamped value.
Example
local x = math.clamp(50, 5, 25); -- 25
remap_val
Function
Maps the value from one range to another range.
Arguments
val
float
Value.
a
float
Lowest source value.
b
float
Highest source value.
c
float
Lowest destination value.
d
float
Highest destination value.
Returns
float
Mapped value.
Example
local mapped = math.remap_val(0.5, 0, 1, 0, 100); -- 50
remap_val_clamped
Function
Maps the value from one range to another range. Additionally, clamps the value based on the source range.
Arguments
val
float
Value.
a
float
Lowest source value.
b
float
Highest source value.
c
float
Lowest destination value.
d
float
Highest destination value.
Returns
float
Mapped value.
Example
local mapped = math.remap_val_clamped(5, 0, 1, 0, 100); -- 100
vec2
Function
An alias to draw.vec2()
.
Example
local vec = math.vec2(5, 5);
vec3
Function
An alias to vector()
.
Example
local vec = math.vec3(5, 12, 5);
Last updated