缓动时四元数旋转360度
Quaternion Rotates 360 Degrees When Easing
我在使用四元数缓和旋转时遇到问题。 ease 似乎工作正常,直到旋转中的一个点决定旋转 360 度以从其起点到达终点。我假设这是因为值从 x 变为 -x。我该如何解决或预防此问题?
这是我的代码
GameObject head;
float speed;
void Start () {
head = GameObject.Find("Camera (eye)");
speed = 1f;
}
void Update () {
transform.rotation = new Quaternion(EaseOutBack(transform.rotation.x, head.transform.rotation.x, Time.deltaTime * speed), EaseOutBack(transform.rotation.y, head.transform.rotation.y, Time.deltaTime * speed), EaseOutBack(transform.rotation.z, head.transform.rotation.z, Time.deltaTime * speed), EaseOutBack(transform.rotation.w, head.transform.rotation.w, Time.deltaTime * speed));
}
public static float EaseOutBack(float start, float end, float value)
{
float s = 1.70158f;
end -= start;
value = (value) - 1;
return end * ((value) * value * ((s + 1) * value + s) + 1) + start;
}
我会尝试在两个四元数之间滑动并将缓动函数应用于 Quaternion.Slerp 的 t 参数。
类似于:
transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));
我在使用四元数缓和旋转时遇到问题。 ease 似乎工作正常,直到旋转中的一个点决定旋转 360 度以从其起点到达终点。我假设这是因为值从 x 变为 -x。我该如何解决或预防此问题?
这是我的代码
GameObject head;
float speed;
void Start () {
head = GameObject.Find("Camera (eye)");
speed = 1f;
}
void Update () {
transform.rotation = new Quaternion(EaseOutBack(transform.rotation.x, head.transform.rotation.x, Time.deltaTime * speed), EaseOutBack(transform.rotation.y, head.transform.rotation.y, Time.deltaTime * speed), EaseOutBack(transform.rotation.z, head.transform.rotation.z, Time.deltaTime * speed), EaseOutBack(transform.rotation.w, head.transform.rotation.w, Time.deltaTime * speed));
}
public static float EaseOutBack(float start, float end, float value)
{
float s = 1.70158f;
end -= start;
value = (value) - 1;
return end * ((value) * value * ((s + 1) * value + s) + 1) + start;
}
我会尝试在两个四元数之间滑动并将缓动函数应用于 Quaternion.Slerp 的 t 参数。
类似于:
transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));