Vector3.SmoothDamp 平滑阻尼


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

Parameters参数

  • current
    The current position.
       当前的位置
  • target
    The position we are trying to reach.
         我们试图接近的位置
       
  • currentVelocity
    The current velocity, this value is modified by the function every time you call it.
       当前速度,这个值由你每次调用这个函数时被修改
  • smoothTime
    Approximately the time it will take to reach the target. A smaller value will reach the target faster.
       到达目标的大约时间,较小的值将快速到达目标
  • maxSpeed
    Optionally allows you to clamp the maximum speed.
         选择允许你限制的最大速度
       
  • deltaTime
    The time since the last call to this function. By default Time.deltaTime.
          自上次调用这个函数的时间。默认为 Time.deltaTime

Description描述

Gradually changes a vector towards a desired goal over time.

随着时间的推移,逐渐改变一个向量朝向预期的目标。

The vector is smoothed by some spring-damper like function, which will never overshoot.  The most common use is for smoothing a follow camera.

向量由一些像弹簧阻尼器函数平滑,这将永远不会超过。最常见的用途是平滑跟随相机。

  • C#

  • JavaScript

using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Transform target;public float smoothTime = 0.3F;private Vector3 velocity = Vector3.zero;void Update() {Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);}}
// Smooth towards the target//平滑朝向目标var target : Transform;var smoothTime = 0.3;private var velocity = Vector3.zero;function Update () {// Define a target position above and behind the target transform//定义一个目标位置在目标变换的上方并且在后面var targetPosition : Vector3 = target.TransformPoint(Vector3(0, 5, -10));// Smoothly move the camera towards that target position//平滑地移动摄像机朝向目标位置transform.position = Vector3.SmoothDamp(transform.position, targetPosition,velocity, smoothTime);}


,