NumberUtil
The NumberUtil module provides utility functions for Lua numbers.
E
¶
The irrational number e.
1 |
|
Tau
¶
Equal to 2π
.
1 |
|
Lerp(min, max, alpha)
¶
Interpolate between two numbers by a certain alpha/percentage. The name "lerp" comes from combining linear interpolation.
Visually, think of a number line ranging from 'min' to 'max' and then move along that line by 'alpha' percent.
1 2 3 4 |
|
LerpClamp(min, max, alpha)
¶
The same as Lerp, except alpha
is clamped between the range of [0, 1]
. This helps avoid the resultant number being out of the input range of [min, max]
.
1 2 |
|
InverseLerp(min, max, num)
¶
The inverse of the Lerp function. It returns the alpha
value between the range of [min, max]
given the num
.
1 2 |
|
Map(n, inMin, inMax, outMin, outMax)
¶
Remaps the range of 'num' from its old range of [inMin, inMax]
to a new range of [outMin, outMax]
. This is useful when needing to convert a range of inputs to a different output. For instance, remapping gamepad stick input to a larger range controlling a vehicle steering wheel.
Mathematically, this is done by doing an inverse lerp with n
on [inMin, inMax]
to get the correct alpha value, and then lerping that alpha value with the range of [outMin, outMax]
.
1 2 |
|
Round(num)
¶
Rounds a number to the nearest whole number.
Internally, this uses the math.floor
and math.ceil
Lua math functions to round the number.
1 2 3 |
|
RoundTo(num, multiple)
¶
Rounds a number to the nearest given multiple. An example would be locking world positions onto a larger grid.
1 2 |
|