public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime);
平滑阻尼插值
表示效果:从current位置到target位置,先加速再减速运动。
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.3F;
private float yVelocity = 0.0F;
void Update()
{
float newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y, ref yVelocity, smoothTime);
transform.position = new Vector3(transform.position.x, newPosition, transform.position.z);
}
}
从部分currentVelocity输出日志可以看到效果。