简体   繁体   English

四元数在缓动时旋转360度

[英]Quaternion Rotates 360 Degrees When Easing

I am encountering an issue when easing the rotation using Quaternions. 使用四元数缓解旋转时遇到问题。 The ease seems to work fine until one point in the rotation it decided to rotate 360 degrees to get from its start point to its end point. 在确定旋转360度(从起点到终点)的某一点之前,这种缓动似乎效果很好。 I am assuming it's because the value is going from x to -x. 我假设这是因为值从x变为-x。 How can I account for or prevent this issue? 我该如何解决这个问题?

Here is my code 这是我的代码

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;
}

I would try slerping between two quaternions and apply the easing function to the t parameter of Quaternion.Slerp. 我将尝试在两个四元数之间进行筛选,并将缓动函数应用于Quaternion.Slerp的t参数。

Something like: 就像是:

transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM