鸟语天空
Mathf.SmoothDamp()
post by:追风剑情 2017-6-9 18:27

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输出日志可以看到效果。

11111.jpg

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容