Mathf.SmoothDamp 平滑阻尼

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

Parameters参数

Description描述

Gradually changes a value towards a desired goal over time.

随着时间的推移逐渐改变一个值到期望值。

The value is smoothed by some spring-damper like function, which will never overshoot. The function can be used to smooth any kind of value, positions, colors, scalars.

这个值就像被一个不会崩溃的弹簧减振器一样被平滑。这个函数可以用来平滑任何类型的值,位置,颜色,标量。

using UnityEngine;
using System.Collections;

public class example : 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);
	}
}
// Smooth towards the height of the target
//平滑到目标高度
var target : Transform;
var smoothTime = 0.3;
private var yVelocity = 0.0;

function Update () {
	var newPosition : float = Mathf.SmoothDamp(transform.position.y, target.position.y,
	yVelocity, smoothTime);
	transform.position = Vector3(transform.position.x, newPosition, transform.position.z);
}
最后修改:2011年2月23日 Wednesday 21:44

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。