Vector3.SmoothDamp 平滑阻尼

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

Parameters参数

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.

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

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);
}
Page last updated: 2011-1-16