Various maths functions. See https://docs.unity3d.com/ScriptReference/Mathf.html for further documentation
Name | Return Type | Description |
---|---|---|
deg2Rad | number Read-only | A constant that you multiply with a value in degrees to convert it to radians |
epsilon | number Read-only | The smallest value that a float can have such that 1.0 plus this does not equal 1.0 |
positiveInfinity | number Read-only | Positive Infinity |
negativeInfinity | number Read-only | Negative Infinity |
pi | number Read-only | The value of Pi |
rad2Deg | number Read-only | A constant that you multiply with a value in radians to convert it to degrees |
The absolute value function
Returns: number (The absolute value of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Abs(0.1)
The arc-cosine function
Returns: number (The angle in radians whose cosine is f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Acos(0.1)
Compares two floating point values if they are similar
Returns: boolean (True if the difference between the values is less than Math.epsilon)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | number | The first value | |
b | number | The second value |
nearlySame = Math:Approximately(0.1000000000000000011, 0.100000000000000001)
The arc-sine function
Returns: number (The angle in radians whose sine is f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Asin(0.1)
The arc-tangent function
Returns: number (The angle in radians whose tangent is f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Atan(0.1)
The two argument arc-tangent function
Returns: number (The angle in radians whose tan is y/x)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
y | number | The numerator value | |
x | number | The denominator value |
result = Math:Atan2(0.1, 3)
The ceiling function
Returns: number (The smallest integer greater to or equal to f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Ceil(0.1)
Clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range
Returns: number (min if f < min, max if f > max otherwise f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value | |
min | number | The minimum value | |
max | number | The maximum value |
result = Math:Clamp(input, -1, 1)
Clamps value between 0 and 1 and returns value
Returns: number (0 if f < 0, 1 if f > 1 otherwise f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value | number | The input value |
result = Math:Clamp01(1.3)
Calculates the closest power of two
Returns: number (The closest power of two)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value | number | The input value |
result = Math:ClosestPowerOfTwo(13)
The cosine function
Returns: number (The cosine of angle f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value in radians |
result = Math:Cos(0.1)
Calculates the shortest difference between two given angles
Returns: number (The smaller of the two angles in degrees between input and target)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | number | The first value in degrees | |
b | number | The second value in degrees |
result = Math:DeltaAngle(1080, 90)
The exponent function
Returns: number (Returns e raised to the specified power)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
power | number | The input value |
result = Math:Exp(100)
The floor function
Returns: number (The largest integer that is less than or equal to the input)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Floor(2.1)
Inverse linear interpolation between two values by given ratio
Returns: number (A value between 0 and 1 representing how far t is between min and max)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
min | number | The minimum value | |
max | number | The maximum value | |
t | number | The input value |
result = Math:InverseLerp(min, max, 23)
Determines whether a value is a power of two
Returns: boolean (The logarithm of f in base b)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value | number | The input value |
isPower = Math:IsPowerOfTwo(value)
Linearly interpolates two floats by a ratio
Returns: number (A value between min and max representing how far t is between 0 and 1)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
min | number | The minimum value | |
max | number | The maximum value | |
t | number | The input value |
result = Math:Lerp(-1, 1, 0.25)
Same as Lerp but takes the shortest path between the specified angles wrapping around a circle
Returns: number (An angle between min and max representing how far t is between 0 and 1)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
min | number | The start angle in degrees | |
max | number | The end angle in degrees | |
a | number | The input value in degrees |
result = Math:LerpAngle(-30, 90, angle)
Same as Math:Lerp but allows extrapolated values
Returns: number (A value representing t scaled from the range 0:1 to a new range min:max)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
min | number | The minimum value | |
max | number | The maximum value | |
t | number | The input value |
result = Math:Lerp(-1, 1, 0.25)
The logarithm of a specified number in a specified base
Returns: number (The logarithm of f in base b)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value | |
b | number | The base |
result = Math:Log(input, 2)
The base 10 logarithm of a specified number
Returns: number (The base 10 logarithm of a specified number)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Log10(0.1)
The larger of two float numbers
Returns: number (The largest of a and b)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | number | The first input value | |
b | number | The second input value |
biggest = Math:Max(a, b)
The largest value in a sequence of float numbers
Returns: number (The largest value in the list)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
values | number[] | A list of numbers |
biggest = Math:Max({1, 4, 6, 2, -3, 32, 5})
The smaller of two float numbers
Returns: number (The smaller of a and b)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
a | number | The first input value | |
b | number | The second input value |
smallest = Min:Min(a, b)
The smallest value in a sequence of float numbers
Returns: number (The smallest value in a sequence of float numbers)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
values | number[] | A list of numbers |
smallest = Math:Min({1, 4, 6, 2, -3, 32, 5})
Moves a value towards a target value by a given amount
Returns: number (The input + or - maxDelta but clamped to it won't overshoot the target value)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
current | number | The input value | |
target | number | The target value | |
maxDelta | number | The largest change allowed each time |
x = Math:MoveTowards(x, 10, 0.5)
The smallest power of two greater than or equal to the specified number
Returns: number (The smallest power of two greater than or equal to the specified number)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
value | number | The input value |
result = Math:NextPowerOfTwo(26)
Samples a two-dimensional Perlin noise map
Returns: number (Returns the value of the perlin noise as coordinates x,y)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | The input value | |
y | number | The power to raise to |
result = Math:PerlinNoise(0.4, 1.2)
Similar to Math:Round except the values alternate between forward and backwards in the range
Returns: number (A value that is never larger than length and never smaller than 0)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
t | number | The input value | |
length | number | The upper limit |
result = Math:PingPong(0.4, 1.2)
The raised to the specified power
Returns: number (Returns f raised to the specified power)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value | |
p | number | The power to raise to |
result = Math:Pow(0.1, 16)
Loops the value t - similar to "clock" arithmetic
Returns: number (A value that is never larger than length and never smaller than 0)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
t | number | The input value | |
length | number | The upper limit |
result = Math:Round(0.1)
The rounding function
Returns: number (The nearest integer value to f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Round(0.1)
The sign function
Returns: number (The sign of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Sign(0.1)
The sine function
Returns: number (The sine of angle f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value in radians |
result = Math:Sin(0.1)
The square root function
Returns: number (The square root of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Sqrt(0.1)
The smoothstep function
Returns: number (The input smoothly interpolated between the range [from, to] by the ratio t)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
from | number | The lower range | |
to | number | The upper range | |
t | number | The input value |
result = Math:SmoothStep(0, 1, 0.5)
The tangent of an angle
Returns: number (The tangent of an angle)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value |
result = Math:Tan(0.1)
The hyperbolic sine function
Returns: number (The hyperbolic sine of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value in radians |
result = Math:Sinh(0.1)
The hyperbolic cosine function
Returns: number (The hyperbolic cosine of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value in radians |
result = Math:Cosh(0.1)
The hyperbolic tangent function
Returns: number (The hyperbolic tangent of f)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
f | number | The input value in radians |
result = Math:Tanh(0.1)