Mathf.SmoothDampAngle 平滑阻尼角度

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

Parameters参数

Description描述

Gradually changes an angle given in degrees towards a desired goal angle over time.

随着时间的推移逐渐改变一个给定的角度到期望的角度。

The value is smoothed by some spring-damper like function. The function can be used to smooth any kind of value, positions, colors, scalars. The most common use is for smoothing a follow camera.

这个值通过一些弹簧减震器类似的功能被平滑。这个函数可以用来平滑任何一种值,位置,颜色,标量。最常见的是平滑一个跟随摄像机。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform target;
	public float smooth = 0.3F;
	public float distance = 5.0F;
	private float yVelocity = 0.0F;
	void Update() {
		float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth);
		Vector3 position = target.position;
		position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance);
		transform.position = position;
		transform.LookAt(target);
	}
}
// A simple smooth follow camera,
// that follows the targets forward direction
//一个简单的平滑跟随摄像机
//跟随目标的朝向

var target : Transform;
var smooth = 0.3;
var distance = 5.0;
private var yVelocity = 0.0;

function Update () {
	// Damp angle from current y-angle towards target y-angle
	//从目前的y角度变换到目标y角度
	var yAngle : float = Mathf.SmoothDampAngle(transform.eulerAngles.y,
	target.eulerAngles.y, yVelocity, smooth);
	// Position at the target
	//target的位置
	var position : Vector3 = target.position;
	// Then offset by distance behind the new angle
	//然后,新角度之后的距离偏移
	position += Quaternion.Euler(0, yAngle, 0) * Vector3 (0, 0, -distance);
	// Apply the position
	//应用位置
	transform.position = position;

	// Look at the target
	//看向目标
	transform.LookAt(target);
}
Page last updated: 2011-4-21