public static Vector3 SmoothDamp (Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed= Mathf.Infinity, float deltaTime= Time.deltaTime);

参数

current当前位置。
target尝试达到的目标。
currentVelocity当前速度,此值由函数在每次调用时进行修改。
smoothTime达到目标所需的近似时间。值越小,达到目标的速度越快。
maxSpeed可以选择允许限制最大速度。
deltaTime自上次调用此函数以来的时间。默认情况下为 Time.deltaTime。

描述

随时间推移将一个向量逐渐改变为所需目标。

向量通过某个类似于弹簧-阻尼的函数(它从不超过目标)进行平滑。 最常见的用法是用于平滑跟随摄像机。

// Smooth towards the target

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; public float smoothTime = 0.3F; private Vector3 velocity = Vector3.zero;

void Update() { // Define a target position above and behind the target transform Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));

// Smoothly move the camera towards that target position transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); } }