Math Module
#math.round number math.round(number value)

Standard rounding function; rounds a value up or down to its nearest whole value.

Example:
local roundedValue = math.round(1.5); -- roundedValue should round up to 2.0
#math.distance number math.distance(number x1, number y1, number x2, number y2) number math.distance(number x1, number y1, number z1, number x2, number y2, number z2)

Standard distance function; it accepts two points and returns their computed distance.

There are two variations of this function: one for 2D distance, and one for 3D. If you supply 4 parameters (x1, y1, x2, y2), the result will be the distance between the 2D points. If 6 parameters are given (x1, y1, z1, x2, y2, z2) the result will be the distance between the 3D points.

Example:
local dist2d = math.distance(0, 0, 1, 1); -- ~1.414 from (0,0) to (1,1) local dist3d = math.distance(0, 0, 0, 1, 1, 1); -- ~1.732 from (0,0,0) to (1,1,1)

Page last updated at 2018-10-03 01:36:11


Copyright 2024