C# 放松时,四元数旋转360度
在使用四元数缓和旋转时,我遇到了一个问题。在旋转过程中的一个点决定旋转360度以从起点到终点之前,这种轻松似乎工作得很好。我假设这是因为值从x到-x。我如何解释或防止此问题 这是我的密码C# 放松时,四元数旋转360度,c#,unity3d,rotation,quaternions,C#,Unity3d,Rotation,Quaternions,在使用四元数缓和旋转时,我遇到了一个问题。在旋转过程中的一个点决定旋转360度以从起点到终点之前,这种轻松似乎工作得很好。我假设这是因为值从x到-x。我如何解释或防止此问题 这是我的密码 GameObject head; float speed; void Start () { head = GameObject.Find("Camera (eye)"); speed = 1f; } void Update () { transform.rotation = new
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;
}
我将尝试在两个四元数之间滑动,并将easing函数应用于Quaternion.Slerp的t参数 比如:
transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));
我将尝试在两个四元数之间滑动,并将easing函数应用于Quaternion.Slerp的t参数 比如:
transform.rotation = Quaternion.Slerp(transform.rotation, head.transform.rotation, EaseOutBack(0, 1, Time.deltaTime * speed));