Mathf
- Abs
- Acos
- Approximately
- Asin
- Atan2
- Atan
- CeilToInt
- Ceil
- Clamp01
- Clamp
- ClosestPowerOfTwo
- Cos
- Deg2Rad
- DeltaAngle
- Epsilon
- Exp
- FloorToInt
- Floor
- Infinity
- InverseLerp
- IsPowerOfTwo
- LerpAngle
- Lerp
- Log10
- Log
- Max
- Min
- MoveTowardsAngle
- MoveTowards
- NegativeInfinity
- NextPowerOfTwo
- PingPong
- PI
- Pow
- Rad2Deg
- Repeat
- RoundToInt
- Round
- Sign
- Sin
- SmoothDampAngle
- SmoothDamp
- SmoothStep
- Sqrt
- Tan
Mathf.SmoothDampAngle 平滑阻尼角度
static function SmoothDampAngle (current : float, target : float, ref currentVelocity : float, smoothTime : float, maxSpeed : float = Mathf.Infinity, deltaTime : float = Time.deltaTime) : float
Parameters参数
-
currentThe current position.
当前的位置。 -
targetThe position we are trying to reach.
我们试图达到的位置。 -
currentVelocityThe current velocity, this value is modified by the function every time you call it.
当前速度,这个值在你访问这个函数的时候会被随时修改。 -
smoothTimeApproximately the time it will take to reach the target. A smaller value will reach the target faster.
要到达目标位置的近似时间,实际到达目标时要快一些。 -
maxSpeedOptionally allows you to clamp the maximum speed.
可选参数,允许你限制的最大速度。 -
deltaTimeThe time since the last call to this function. By default Time.deltaTime.
上次调用该函数到现在的时间。缺省为Time.deltaTime。
Description描述
Gradually changes an angle given in degrees towards a desired goal angle over time.
随着时间的推移逐渐改变一个给定的角度到期望的角度。
The value is smoothed by some spring-damper like function. The function can be used to smooth any kind of value, positions, colors, scalars. The most common use is for smoothing a follow camera.
这个值通过一些弹簧减震器类似的功能被平滑。这个函数可以用来平滑任何一种值,位置,颜色,标量。最常见的是平滑一个跟随摄像机。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform target;
public float smooth = 0.3F;
public float distance = 5.0F;
private float yVelocity = 0.0F;
void Update() {
float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth);
Vector3 position = target.position;
position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance);
transform.position = position;
transform.LookAt(target);
}
}
// A simple smooth follow camera,
// that follows the targets forward direction
//一个简单的平滑跟随摄像机
//跟随目标的朝向
var target : Transform;
var smooth = 0.3;
var distance = 5.0;
private var yVelocity = 0.0;
function Update () {
// Damp angle from current y-angle towards target y-angle
//从目前的y角度变换到目标y角度
var yAngle : float = Mathf.SmoothDampAngle(transform.eulerAngles.y,
target.eulerAngles.y, yVelocity, smooth);
// Position at the target
//target的位置
var position : Vector3 = target.position;
// Then offset by distance behind the new angle
//然后,新角度之后的距离偏移
position += Quaternion.Euler(0, yAngle, 0) * Vector3 (0, 0, -distance);
// Apply the position
//应用位置
transform.position = position;
// Look at the target
//看向目标
transform.LookAt(target);
}
最后修改:2011年4月21日 Thursday 15:08