| current | 当前位置。 | 
| target | 尝试达到的目标。 | 
| currentVelocity | 当前速度,此值由函数在每次调用时进行修改。 | 
| smoothTime | 达到目标所需的近似时间。值越小,达到目标的速度越快。 | 
| maxSpeed | 可以选择允许限制最大速度。 | 
| deltaTime | 自上次调用此函数以来的时间。默认情况下为 Time.deltaTime。 | 
随时间推移将以度为单位给定的角度逐渐改变为所需目标角度。
值通过某个类似于弹簧-阻尼的函数(它不会超过目标)进行平滑。该函数可以用于平滑任何类型的值、位置、颜色、标量。 最常见的用法是用于平滑跟随摄像机。
using UnityEngine;
public class Example : MonoBehaviour { //A simple smooth follow camera, // that follows the targets forward direction
Transform target; float smooth = 0.3f; float distance = 5.0f; float yVelocity = 0.0f;
void Update() { // Damp angle from current y-angle towards target y-angle float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth); // Position at the target Vector3 position = target.position; // Then offset by distance behind the new angle position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance); // Apply the position transform.position = position;
// Look at the target transform.LookAt(target); } }