Unity Mathf関数 ( Static Functions - 3 )
小数点以下を切り上げ。
Mathf.Ceil ( 10.7f );
→ 11.0f
小数点以下をInt型に切り上げ。
Mathf.CeilToInt ( 10.7f );
→ 11
小数点以下を切り捨て。
Mathf.Floor ( 10.7f );
→ 10.0f
小数点以下をInt型に切り上げ。
Mathf.FloorToInt ( 10.7f );
→ 10
最大・最小値を設定し、制限をかける。
Ex: transform.position.z = Mathf.Clamp ( transform.position.z, -100, 100 );
0 から1 の値を返えす。
Ex: val = Mathf.Clamp01 ( transform.position.z );
数値を2のべき乗に最も近い値を返す。
Mathf.ClosestPowerOfTwo(36);
→ 32
値以上の最も近い2 のべき乗を返す。
Mathf.NextPowerOfTwo(36);
→ 64
角度の最短の差を返す。
Mathf.DeltaAngle ( 200, 60 );
→ -140
平方根。
Mathf.Sqrt (3);
累乗。
Mathf.Exp (3);
2点間値を割合で表す。※割合は0.0から1.0。
Mathf.Lerp ( 10, 20, 0.6f );
2点間をLerp関数で求める。
Mathf.InverseLerp ( a, b, b/4 );
2点間の角度を割合で表す。※割合は0.0から1.0。
Mathf.LerpAngle ( 0, 90, 0.7f );
指数。
Mathf.Pow(6, 3)
→ 216
対数。
Mathf.Log( 32, 2 );
→ 5
基数10の対数。
Mathf.Log10 (100);
→ 2
指定位置から、ターゲット位置までを指定スピードで移動。
Mathf.MoveTowards ( current_pos, target_pos, speed * Time.deltaTime );
指定角度から、ターゲット角度までを指定スピードで回転。
Mathf.MoveTowardsAngle ( current_ang, target_ang, speed * Time.deltaTime );
0から指定の値までを折り返す。
Mathf.PingPong ( now_Val, 10 );
0から指定の値までを繰り返す。
Mathf.Repeat ( now_Val, 10 );
Float型のまま整数に四捨五入。
Mathf.Round ( 10.7f );
→ 11.0f
Int型に切り捨て。
Mathf.RoundToInt ( 10.7f );
→ 10
符号逆転。
Mathf.Sign ( -10 );
→ 10
徐々に時間をかけて目標へ向かう。
Mathf.SmoothDamp ( current_pos, target_pos, nowVelocity, smoothTime );
徐々に時間をかけて目標の角度へ向かう。
Mathf.SmoothDampAngle ( current_ang, target_ang, nowVelocity, smoothTime );
時間をかけて2 点間の移動をスムーズ(Lerp)に行う。
Mathf.SmoothStep ( current_pos, target_pos, now_pos );
Mathf.Ceil ( 10.7f );
→ 11.0f
小数点以下をInt型に切り上げ。
Mathf.CeilToInt ( 10.7f );
→ 11
小数点以下を切り捨て。
Mathf.Floor ( 10.7f );
→ 10.0f
小数点以下をInt型に切り上げ。
Mathf.FloorToInt ( 10.7f );
→ 10
最大・最小値を設定し、制限をかける。
Ex: transform.position.z = Mathf.Clamp ( transform.position.z, -100, 100 );
0 から1 の値を返えす。
Ex: val = Mathf.Clamp01 ( transform.position.z );
数値を2のべき乗に最も近い値を返す。
Mathf.ClosestPowerOfTwo(36);
→ 32
値以上の最も近い2 のべき乗を返す。
Mathf.NextPowerOfTwo(36);
→ 64
角度の最短の差を返す。
Mathf.DeltaAngle ( 200, 60 );
→ -140
平方根。
Mathf.Sqrt (3);
累乗。
Mathf.Exp (3);
2点間値を割合で表す。※割合は0.0から1.0。
Mathf.Lerp ( 10, 20, 0.6f );
2点間をLerp関数で求める。
Mathf.InverseLerp ( a, b, b/4 );
2点間の角度を割合で表す。※割合は0.0から1.0。
Mathf.LerpAngle ( 0, 90, 0.7f );
指数。
Mathf.Pow(6, 3)
→ 216
対数。
Mathf.Log( 32, 2 );
→ 5
基数10の対数。
Mathf.Log10 (100);
→ 2
指定位置から、ターゲット位置までを指定スピードで移動。
Mathf.MoveTowards ( current_pos, target_pos, speed * Time.deltaTime );
指定角度から、ターゲット角度までを指定スピードで回転。
Mathf.MoveTowardsAngle ( current_ang, target_ang, speed * Time.deltaTime );
0から指定の値までを折り返す。
Mathf.PingPong ( now_Val, 10 );
0から指定の値までを繰り返す。
Mathf.Repeat ( now_Val, 10 );
Float型のまま整数に四捨五入。
Mathf.Round ( 10.7f );
→ 11.0f
Int型に切り捨て。
Mathf.RoundToInt ( 10.7f );
→ 10
符号逆転。
Mathf.Sign ( -10 );
→ 10
徐々に時間をかけて目標へ向かう。
Mathf.SmoothDamp ( current_pos, target_pos, nowVelocity, smoothTime );
徐々に時間をかけて目標の角度へ向かう。
Mathf.SmoothDampAngle ( current_ang, target_ang, nowVelocity, smoothTime );
時間をかけて2 点間の移動をスムーズ(Lerp)に行う。
Mathf.SmoothStep ( current_pos, target_pos, now_pos );
テーマ : Unityゲーム制作
ジャンル : コンピュータ