Lua · Variables · Helpers
math extras
Additions to the standard math library.
| Function | What it does |
|---|---|
math.clamp(v, min, max) | Keeps v inside min to max. |
math.lerp(a, b, t) | a + (b - a) * t. |
math.round(v) | Nearest whole number (halves go up). |
math.distance(a, b) | Distance between two vectors. |
math.angle_to(from, to) | View angles that look from one point at another, in degrees (negative pitch is up, the game's own convention). |
#math.clamp
math.clamp(v, min, max)Keeps v inside min to max.
Returns
number
-
#math.lerp
math.lerp(a, b, t)a + (b - a) * t.
Returns
number
-
Example
shown = math.lerp(shown, target, 1 - math.exp(-12 * globals.frametime()))#math.round
math.round(v)Nearest whole number (halves go up).
Returns
integer
-
#math.distance
math.distance(a, b)Distance between two vectors.
Returns
number
Game units.
#math.angle_to
math.angle_to(from, to)View angles that look from one point at another, in degrees (negative pitch is up, the game's own convention).
Returns
number1
pitch
number2
yaw