Mathf.abs Absolute Value
Calculates and returns the absolute value of the specified parameter F.
mathf.acos Inverse cosine
static function Acos (f:float): float
Calculates and returns the inverse cosine of the number specified in Parameter F, in radians.
mathf.approximately Approximate
static function approximately (A:float, b:float): bool
Compare two floating-point values to see if they are very close, because the floating-point values are not accurate, it is not recommended to use equals to compare them. For example, 1.0==10.0/10.0 may not return true.
public class Example:monobehaviour {
Publicvoid Awake () {
if (mathf.approximately (1.0F, 10.0f/10.0f))
Print ("Same");
}
}
Mathf.asin anyway Chord
static function Asin (f:float): float
Calculates and returns the inverse sine of the number specified in Parameter F, in radians.
mathf.atan2 anyway cut
static function Atan2 (Y:float, x:float): float
Calculates and returns the inverse tangent value of the y/x in radians. The return value represents a diagonal angle relative to right triangle, where x is the edge length and y is the edge length.
The return value is the angle between the x-axis and a two-dimensional vector starting at 0 end at (x, y).
public class Example:monobehaviour {
Publictransform Target;
Voidupdate () {
Vector3relative = transform. Inversetransformpoint (target.position);
Floatangle = Mathf.atan2 (relative.x, relative.z) * MATHF.RAD2DEG;
Transform. Rotate (0,angle, 0);
}
}
Mathf.atan anyway cut
static function Atan (f:float): float
Calculates and returns the inverse tangent of the number specified in the parameter F. The return value is between the pi of negative two points and the Pi of positive two.
mathf.ceiltoint Minimum Integer
static function Ceiltoint (f:float): int
Returns the smallest integer greater than or equal to F.
Mathf.ceil Upper Value
static function Ceil (f:float): float
Returns f Specifies the upper value of the number or expression. The upper value of the number is the nearest integer greater than or equal to the number.
mathf.clamp01 Limit 0~1
static function Clamp01 (value:float): float
Limit value to 0, 1, and return value. Returns 0 if value is less than 0. If value is greater than 1, returns 1, otherwise returns value.
Mathf.clamp Restrictions
static function Clamp (Value:float, Min:float, max:float): float
Limits the value of values between Min and Max, and returns min if value is less than min. Returns max if value is greater than max, otherwise returns value
static function Clamp (Value:int, Min:int, max:int): int
Limits the value of values between Min and Max, and returns value.
Mathf.closestpoweroftwo Recent two-time Square
static function Closestpoweroftwo (value:int): int
Returns the number of times the nearest 2 from value.
Mathf.cos cosine
static function Cos (f:float): float
Returns the cosine of the angle specified by the parameter F (a value between 1.0 and 1.0).
Mathf.deg2rad degree Turn radian
static Var deg2rad:float
Conversion constants in degrees to radians. (Read only)
This Equals (PI * 2)/360.
Mathf.Mathf.Rad2Deg radian Degree of change
static Var rad2deg:float
Conversion constants of radians to degrees. (Read only)
This is equal to (PI * 2).
mathf.deltaangle Increment Angle
static function Deltaangle (Current:float, target:float): float
Calculates the shortest difference between a given two corners.
Prints 90
Debug.Log (Mathf.deltaangle (1080,90));
Mathf.epsilon Small Positive number
static Var epsilon:float
A very small floating-point value. (Read only)
The smallest floating-point value, different from 0.
The following rules:
-Anyvalue + Epsilon = Anyvalue
-Anyvalue-epsilon = Anyvalue
-0 + Epsilon = Epsilon
-0-epsilon =-epsilon
A value between an arbitrary number and a epsilon will cause a truncation error to occur at any number.
public class Example:monobehaviour {
Boolisequal (float A, float b) {
if (a >= b-mathf.epsilon && a <= B + Mathf.epsilon)
Returntrue;
Else
Returnfalse;
}
}
Mathf.exp Index
static function Exp (power:float): float
Returns the value of the power sub-side of E.
mathf.floortoint Maximum integer
static function Floortoint (f:float): int
Returns the largest integer, less than or equal to F.
Mathf.floor Lower Value
static function Floor (f:float): float
Returns the lower value of the number or expression specified in parameter F. The lower value is the nearest integer less than or equal to the specified number or expression.
mathf.infinity Positive Infinity
static Var infinity:float
denotes positive infinity, i.e. infinity, ∞ (Read only)
mathf.inverselerp anti-interpolation values
Calculates the LERP parameter between two values. That is, value in the ratio between from and to.
Now the parameter is 3/5.
Float parameter =mathf.inverselerp (walkspeed, runspeed, speed);
Mathf.ispoweroftwo whether the power of 2
static function Ispoweroftwo (value:int): bool
Returns True if the value is a power of 2.
Prints false
Debug.Log (Mathf.ispoweroftwo (7));
Prints true
Debug.Log (Mathf.ispoweroftwo (32));
mathf.lerpangle Interpolation Angle
static function Lerpangle (A:float, B:float, t:float): float
As with the lerp principle, when they surround 360 degrees, make sure the interpolation is correct.
A and B are representative degrees.
public class Example:monobehaviour {
Publicfloat minangle = 0.0F;
Publicfloat maxangle = 90.0F;
Voidupdate () {
Floatangle = Mathf.lerpangle (Minangle, Maxangle, time.time);
transform.eulerangles= New Vector3 (0, angle, 0);
}
}
mathf.lerp interpolation
static function Lerp (From:float, To:float, t:float): float
Returns the interpolation between A and b based on the floating-point number T, which is limited to 0~1.
When t = 0 returns from, when t = 1 returns to. When t = 0.5 returns the mean of the From and to.
mathf.log10 logarithm of radix 10
static function Log10 (f:float): float
Returns the logarithm of F, with a base of 10.
Mathf.Log logarithm
static function Log (F:float, p:float): float
Returns the logarithm of the parameter F.
Logarithm of 6 in base 2
Logarithm with base 6 of 2
Prints 2.584963
Print (Mathf.Log (6, 2));
Mathf.max Maximum Value
static function Max (A:float, b:float): float
static function Max (params values:float[]): float
Returns the largest value in two or more values.
mathf.min Minimum Value
static function Min (A:float, b:float): float
static function Min (params values:float[]): float
Returns the smallest value in two or more values.
Mathf.movetowardsangle Moving Angle
static function Movetowardsangle (Current:float, Target:float, maxdelta:float): float
Like Movetowards, but when they surround 360 degrees, make sure the interpolation is correct.
The variable current and target are as degrees. For optimization reasons, Maxdelta negative values are not supported and may cause oscillation. Push current from the target angle and add a 180-degree angle instead.
mathf.movetowards Move to
static function Movetowards (Current:float, Target:float, maxdelta:float): float
Changes a current value closer to the target value.
This is actually the same as MATHF.LERP, but the function will ensure that our speed does not exceed Maxdelta. Maxdelta a negative value to push the target away from.
mathf.negativeinfinity Negative Infinity
static Var negativeinfinity:float
Indicates negative infinity, i.e. infinity,-∞ (Read only)
Mathf.nextpoweroftwo The power of the next 2
Mathf.pingpong Table Tennis
static function Pingpong (T:float, length:float): float
0 to length between round trips. The T value will never be greater than the value of length and will never be less than 0.
The returned value would move back and Forthbetween 0 and length.
The return value moves back and forth between 0 and length.
Mathf.pi Pi
static Var pi:float
Pi (read pai) value, that is, the value of pi (π) 3.14159265358979323846 ... (Read only)
Mathf.pow Second Party
static function Pow (F:float, p:float): float
Calculates and returns the P-second side of F.
Mathf.repeat Repeat
static function Repeat (T:float, length:float): float
The loop value t,0 between length. The T value will never be greater than the value of length and will never be less than 0.
This is similar to the modulo operator, but you can use floating-point numbers.
public class Example:monobehaviour {
Voidupdate () {
transform.position= New Vector3 (Mathf.repeat (Time.time, 3), transform.position.y,transform.position.z);
}
}
mathf.roundtoint rounding to integers
static function Roundtoint (f:float): int
Returns the value specified by F rounded to the nearest integer.
If the number is at the end of. 5, it is in the middle of two integers, either even or odd, returning even numbers.
Mathf.round Rounding
static function Round (f:float): float
Returns the nearest integer to which the floating-point number f is rounded.
If the number is at the end of. 5, it is in the middle of two integers, either even or odd, returning even numbers.
mathf.sign Symbol
static function sign (f:float): float
Returns the sign of F.
When F is positive or 0 returns 1, negative returns-1.
mathf.sin Sine
static function Sin (f:float): float
Calculates and returns the sinusoidal value of the angle f specified in radians.
Mathf.smoothdampangle Smoothing Damping Angle
static function Smoothdampangle (Current:float, target:float, ref currentvelocity:float, Smoothtime:float,maxspeed : float = mathf.infinity, deltatime:float = time.deltatime): float
Parameters
Current
The current location.
Target
We tried to reach the position.
Currentvelocity
Current speed, this value will be modified at any time when you visit this function.
Smoothtime
The target faster.
To reach the approximate time of the target location, it is quicker to actually reach the target.
Maxspeed
Optional parameters that allow you to limit the maximum speed.
Deltatime
The time that the function was last called to now. The default is Time.deltatime.
Gradually change a given angle to the desired angle over time.
This value is smoothed by a similar function of some spring dampers. This function can be used to smooth any kind of value, position, color, scalar. The most common is to smooth a follow-up camera.
A simple smooth follow-up camera
Follow the direction of the target
public class Example:monobehaviour {
Publictransform Target;
Publicfloat smooth = 0.3F;
Publicfloat distance = 5.0F;
Privatefloat yvelocity = 0.0F;
Voidupdate () {
change from current y angle to target y angle
Floatyangle = Mathf.smoothdampangle (Transform.eulerangles.y, target.eulerangles.y,ref yVelocity, smooth);
Location of Target
Vector3position = target.position;
Then, the distance offset after the new angle
position+= quaternion.euler (0, Yangle, 0) * New Vector3 (0, 0,-distance);
Application Location
transform.position= position;
Look at the target.
Transform. LookAt (target);
}
}
Mathf.smoothdamp Smoothing Damping
static function Smoothdamp (Current:float, target:float, ref currentvelocity:float, Smoothtime:float,maxspeed:flo at = mathf.infinity, deltatime:float = time.deltatime): float
Parameters
Current
The current location.
Target
We tried to reach the position.
Currentvelocity
Current speed, this value will be modified at any time when you visit this function.
Smoothtime
To reach the approximate time of the target location, it is quicker to actually reach the target.
Maxspeed
Optional parameters that allow you to limit the maximum speed.
Deltatime
The time that the function was last called to now. The default is Time.deltatime.
Describe
Gradually change a value to expectations over time.
This value is as smooth as a spring damper that does not crash. This function can be used to smooth any type of value, position, color, scalar.
public class Example:monobehaviour {
Publictransform Target;
Publicfloat smoothtime = 0.3F;
Privatefloat yvelocity = 0.0F;
Voidupdate () {
Floatnewposition = Mathf.smoothdamp (TRANSFORM.POSITION.Y, TARGET.POSITION.Y, refyvelocity, smoothTime);
transform.position= New Vector3 (transform.position.x, newposition, transform.position.z);
}
}
Mathf.smoothstep Smoothing Interpolation
static function Smoothstep (From:float,to:float, t:float): float
Similar to Lerp, interpolation between the minimum and maximum values, and gradually fade out at the limit.
public class Example:monobehaviour {
Publicfloat minimum = 10.0F;
Publicfloat maximum = 20.0F;
Voidupdate () {
transform.position= New Vector3 (Mathf.smoothstep (minimum, maximum, time.time), 0, 0);
}
}
mathf.sqrt Square Root
static function Sqrt (f:float): float
Calculates and returns the square root of F.
Mathf.tan Tangent
static function Tan (f:float): float
Calculates and returns the tangent of the angle specified in radians.
Unity MATHF Math Operations (C #)