The SMath class contains common math functions, see also SVector and SQuaternion for Vector and Quaternion related math functions.
Members
Random
Returns a random float between 0 and 1 (inclusive)
local randomNumber = Space.Math.Random();
Space.Log(randomNumber);
-- prints 0.689094245433807
RandomRange
float RandomRange
(float min, float max);
Returns a random float between min and max (inclusive)
local min = 100.0;
local max = 500.0;
local randomNumber = Space.Math.RandomRange(min, max );
Space.Log(randomNumber);
-- prints 0206.659149169922
RandomInteger
int RandomInteger
(int min, int max);
Returns a random float between min (inclusive) and max (exclusive)
local min = 50;
local max = 75;
local randomInteger = Space.Math.RandomInteger(min, max);
Space.Log(randomInteger);
-- prints 52
Abs
Returns the absolute value of 'val'
local value = -4.2
local absoluteNum = Space.Math.Abs(value);
Space.Log(absoluteNum);
-- prints 4 [BUG] should be 4.2
Abs
Returns the absolute value of 'val'
local value = -4
local absoluteNum = Space.Math.Abs(value);
Space.Log(absoluteNum);
-- prints 4
Acos
Returns the arc cosine value of 'val'
local angle = 0.5;
local arcCosine = Space.Math.Acos(angle);
Space.Log(arcCosine);
-- prints 1.04719758033752 (radians) which is 60 degrees
Approximately
bool Approximately
(float a, float b);
True if the difference between a and b is less than epsilon
local a = 5.0;
local b = 5;
local approx1 = Space.Math.Approximately(a, b);
Space.Log(approx1);
-- prints true
local a = 5.01;
local b = 5.0;
local approx2 = Space.Math.Approximately(a, b);
Space.Log(approx2);
-- prints false
local a = 5.01;
local b = 5.0;
local approx3 = Space.Math.Approximately(a, b);
Space.Log(approx3);
-- prints false
Asin
Returns the arc sine value of 'val'
No example provided yet
Atan
Returns the arc tangent value of 'val'
No example provided yet
Atan2
bool Atan2
(float y, float x);
Returns the arc tangent of y/x
No example provided yet
Ceil
Returns the ceil value of 'val' as an integer
No example provided yet
Clamp
float Clamp
(float val, float min, float max);
Clamps val between min and max, and returns the result
No example provided yet
Clamp01
float Clamp01
(float val);
Clamps val between 0 and 1, and returns the result
No example provided yet
ClosestPowerOfTwo
int ClosestPowerOfTwo
(int val);
Returns the closest power of two to val
No example provided yet
Cos
Returns the cosine of val
No example provided yet
DeltaAngle
float DeltaAngle
(float current, float target);
Returns the difference in degrees between two values (e.g. 350' and 17' returns 27')
No example provided yet
Exp
Returns Exp of val
No example provided yet
Floor
Returns floor of val, converted to an int
No example provided yet
GammaToLinearSpace
float GammaToLinearSpace
(float val);
Converts a colour value from Gamma to Linear Space (Pow 2.2)
No example provided yet
InverseLerp
float InverseLerp
(float a, float b, float val);
Returns the percentage between a and b that 'val' is on a line (opposite of Lerp)
No example provided yet
IsPowerOfTwo
bool IsPowerOfTwo
(int val);
Returns true if val is a power of two
No example provided yet
Lerp
float Lerp
(float a, float b, float val);
Interpolates between 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1
No example provided yet
LerpAngle
float LerpAngle
(float a, float b, float val);
Interpolates between angles 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1
No example provided yet
LerpUnclamped
float LerpUnclamped
(float a, float b, float val);
Interpolates between 'a' and 'b' based on 'val', assuming 'val' is between 0 and 1, but unbounded (allowing higher/lower values)
No example provided yet
GammaToLinearSpace
float GammaToLinearSpace
(float val);
Converts a colour value from Linear to Gamma Space (Pow 1/2.2)
No example provided yet
Log
Returns the natural logarithm for 'val'
No example provided yet
Log
float Log
(float val, float p);
Returns the logarithm of 'p' for 'val'
No example provided yet
Log10
Returns the Log10 value for 'val'
No example provided yet
Max
float Max
(float a, float b);
Returns higher of 'a' or 'b'
No example provided yet
Min
float Min
(float a, float b);
Returns lower of 'a' or 'b'
No example provided yet
MoveTowards
float MoveTowards
(float value, float target, float delta);
Move value to target, but by no more than delta
No example provided yet
MoveTowardsAngle
float MoveTowardsAngle
(float value, float target, float delta);
Move angle value to target, but by no more than delta
No example provided yet
NextPowerOfTwo
int NextPowerOfTwo
(int val);
Return the next power of two larger or equal to val
No example provided yet
PerlinNoise
float PerlinNoise
(float x, float y);
Return 2D Perlin noise for coordinates x and y
No example provided yet
PingPong
float PingPong
(float val, float length);
Return a value between 0 and length that oscillates upwards and back based on the position of 'val'
No example provided yet
Pow
float Pow
(float x, float y);
Return x raised to y power
No example provided yet
Repeat
float Repeat
(float val, float length);
Return a value between 0 and length that returns to 0 after exceeding length based on 'val'
No example provided yet
Round
Returns the nearest integer value to val
No example provided yet
Sign
Returns either 1 or -1 based on the sign of 'val'
No example provided yet
Sin
Returns the sine of val
No example provided yet
SmoothStep
float SmoothStep
(float from, float to, float val);
Similar to Lerp but moves slowly closer to the edges ('Spherical Lerp')
No example provided yet
Sqrt
Returns the square root of val
No example provided yet
Tan
Returns the tangent value of 'val'
No example provided yet
Scripting Portal
|
|
Common
|
|
|
Key Classes
|
|
|
Helper Classes
|
|
|
Scripting samples and tutorials
|
|
|