Quaternion.Slerp
Description
Spherically interpolates between from
and to
by t.从from到to在t位置的球状插值
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Transform from; public Transform to; public float speed = 0.1F; void Update() { transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.time * speed); } }
这是untiy3d官方文档的介绍。我有不明白的地方,1是t的范围;2是例子t的赋值是Time.time * speed,Time.time是系统启动到现在的时间,可以很大。3是Slerp与Lerp的区别。
参考Vector.Slerp。1、t的范围 [0...1]。2、t的赋值应该与Time.deltaTime相关,才能达到平滑的过度。Vector3.Slerp
Description
Spherically interpolates between two vectors.两个向量的球状插值。
Interpolates between
from
andto
by amountt
. The difference between this and linear interpolation (aka, "lerp") is that the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated by the angle and its magnitude is interpolated between the magnitudes offrom
andto
.从from到to在t位置的球状插值。于线性插值lerp不同的是向量被当做方向而不是空间中的点。返回的插值方向是在from和to间通过角度和幅度插值得到的。
/t/ is clamped between [0...1]. See Also: Lerp function.
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Transform sunrise; public Transform sunset; public float journeyTime = 1.0F; private float startTime; void Start() { startTime = Time.time; } void Update() { Vector3 center = (sunrise.position + sunset.position) * 0.5F; center -= new Vector3(0, 1, 0); Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center; float fracComplete = (Time.time - startTime) / journeyTime; transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center; } }3、参考Quaternion.Lerp
Description
Interpolates between
from
andto
byt
and normalizes the result afterwards.从from到to在t位置的插值,然后标准化结果。This is faster than Slerp but looks worse if the rotations are far apart.这个比Slerp快,但是旋转很远的话很糟糕。
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Transform from; public Transform to; public float speed = 0.1F; void Update() { transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed); } }在网上查到的不同点:Slerp:在from和to间通过角度和幅度插值得到的。Lerp:是线性插值。