# Mathf.SmoothDampAngle 平滑阻尼角度

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 position.
当前的位置。
• target
The position we are trying to reach.
我们试图达到的位置。
• currentVelocity
The current velocity, this value is modified by the function every time you call it.
当前速度，这个值在你访问这个函数的时候会被随时修改。
• smoothTime
Approximately the time it will take to reach the target. A smaller value will reach the target faster.
要到达目标位置的近似时间，实际到达目标时要快一些。
• maxSpeed
Optionally allows you to clamp the maximum speed.
可选参数，允许你限制的最大速度。
• deltaTime
The 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);
}``````
Page last updated: 2011-4-21