Mathf
The Mathf class provides a collection of common mathematical functions and constants. It includes methods for basic arithmetic operations, trigonometric functions, interpolation, and utility functions for working with angles and values. This class is essential for performing mathematical calculations in Unity scripts and is commonly used for game mechanics, animations, and physics calculations.
Properties
The constant used to convert degrees to radians.
A tiny floating point value used for comparisons.
A representation of positive infinity.
A representation of negative infinity.
The mathematical constant pi.
The constant used to convert radians to degrees.
Methods
Returns the absolute value of the given value.
Parameters
value
Returns
Returns the arc-cosine of the given value in radians.
Parameters
f
Returns
Compares two floating point values and returns true if they are approximately equal.
Parameters
a
b
Returns
Returns the arc-sine of the given value in radians. Bruh.
Parameters
f
Returns
Returns the arc-tangent of the given value in radians.
Parameters
f
Returns
Returns the arc-tangent of y/x in radians.
Parameters
y
x
Returns
Returns the smallest integer greater than or equal to the given value.
Parameters
f
Returns
Returns the smallest integer greater than or equal to the given value.
Parameters
f
Returns
Clamps the given value between the minimum and maximum values.
Parameters
value
min
max
Returns
Clamps the given value between 0 and 1.
Parameters
value
Returns
Returns the closest power of two to the given value.
Parameters
value
Returns
Returns the cosine of the given angle in radians.
Parameters
a
Returns
Calculates the shortest difference between two given angles.
Parameters
current
target
Returns
Returns e raised to the power of the given value.
Parameters
power
Returns
Returns the largest integer less than or equal to the given value.
Parameters
f
Returns
Calculates the linear parameter t that produces the interpolant value within the range [a, b].
Parameters
a
b
value
Returns
Returns true if the given value is a power of two.
Parameters
value
Returns
Linearly interpolates between two values.
Parameters
a
b
t
Returns
Linearly interpolates between two angles in degrees.
Parameters
a
b
t
Returns
Linearly interpolates between two values without clamping the interpolant.
Parameters
a
b
t
Returns
Returns the natural logarithm of the given value.
Parameters
f
Returns
Returns the base-10 logarithm of the given value.
Parameters
f
Returns
Returns the largest of two values.
Parameters
a
b
Returns
Returns the smallest of two values.
Parameters
a
b
Returns
Moves a value towards a target value by a maximum delta.
Parameters
current
target
maxDelta
Returns
Moves an angle towards a target angle by a maximum delta.
Parameters
current
target
maxDelta
Returns
Returns the next power of two that is greater than or equal to the given value.
Parameters
value
Returns
Ping-pongs the value t, so that it is never larger than length and never smaller than 0.
Parameters
t
length
Returns
Returns f raised to power p.
Parameters
f
p
Returns
Loops the value t, so that it is never larger than length and never smaller than 0.
Parameters
t
length
Returns
Returns the value rounded to the nearest integer.
Parameters
f
Returns
Returns the sign of the given value.
Parameters
a
Returns
Returns the sine of the given angle in radians.
Parameters
a
Returns
Gradually changes a value towards a target value over time.
Parameters
current
target
currentV
smoothTime
maxSpeed
deltaTime
Returns
Gradually changes an angle towards a target angle over time.
Parameters
current
target
currentV
smoothTime
maxSpeed
deltaTime
Returns
Interpolates between two values using a smooth step function.
Parameters
from
to
t
Returns
Returns the square root of the given value.
Parameters
f
Returns
Returns the tangent of the given angle in radians.
Parameters
a
Returns
Updated 12 days ago