Mathf.SmoothDamp()

作者:追风剑情 发布于:2017-6-9 18:27 分类:Unity3d

public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime);

平滑阻尼插值

表示效果:从current位置到target位置,先加速再减速运动。

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ExampleClass : MonoBehaviour
  5. {
  6. public Transform target;
  7. public float smoothTime = 0.3F;
  8. private float yVelocity = 0.0F;
  9. void Update()
  10. {
  11. float newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y, ref yVelocity, smoothTime);
  12. transform.position = new Vector3(transform.position.x, newPosition, transform.position.z);
  13. }
  14. }

从部分currentVelocity输出日志可以看到效果。

11111.jpg

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号