HomeIndex

Math Functions

distance(p1,p2)
Returns the distance between two numbers or points
local d = distance(50,100) local d = distance(point(10,10), point(100,75))
ord(string)
Converts the first character of a string into an ascii int
ch = ord("a") // ch is 97
chr(ch)
Converts an ascii int to a string char.
s = chr(97) // s is "a"
sin(angle)
Returns the sin of an angle.
The angle is in degrees.
cos(angle)
Returns the cos of an angle.
The angle is in degrees.
pow(num1,num2)
Returns num1 to the power of num2
abs(num)
Returns the absolute value of num
n = abs(-9) // n is 9
min(num1, num2)
Returns the lowest of num1 and num2
n = min(90, 100) // n is 90
max(num1, num2)
Returns the highest of num1 and num2
n = min(90, 100) // n is 100
clamp(num,lower,upper)
Clamps num between lower and upper
v = 50 n = clamp(v, 0, 100) // n is 50 v = -10 n = clamp(v, 0, 100) // n is 0 v = 130 n = clamp(v, 0, 100) // n is 100 v = -50 n = clamp(v, 100, 0) // n is 100
lerp(v1,v2,time)
Returns the linear interpolation between v1 and v2 base on time
time can also be thought if as a percent of the way from v1 to v2
n = lerp(100, 200, 0.5) // n = 150 n = lerp(100, 200, 0.0) // n = 100 n = lerp(100, 200, 1.0) // n = 200 n = lerp(100, 200, 0.25) // n = 125 n = lerp(100, 200, -0.5) // n = 100 n = lerp(100, 200, 2.33) // n = 200