缓和时四元数旋转360度

时间:2016-12-12 21:14:43

标签: c# unity3d rotation quaternions

使用Quaternions缓解旋转时遇到问题。轻松似乎工作正常,直到旋转中的一个点决定旋转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;
}

1 个答案:

答案 0 :(得分:2)

我会尝试在两个四元数之间进行slerping,并将缓动函数应用于Quaternion.Slerp的t参数。

类似的东西:

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