Quaternion.Slerp() Problem
why Quaternion.Slerp() function draw the green line, not the red line;
Slerp() is not make the shortest path?
if i want to rotate GameObject follow the red line, how can i do?
void Update(){
Quaternion startRot = Quaternion.Euler(0, 0, 0);
Quaternion targetRot = Quaternion.Euler(50, 200, 50);
var startPos = startRot * (Vector3.forward * 4);
for (int i = 0; i <= 20; i++)
{
var rot = Quaternion.Slerp(startRot, targetRot, i / 20f);
var endPos = rot * (Vector3.forward * 4);
Debug.DrawLine(startPos, endPos, new Color(0, 1, 0, 1f));
startPos = endPos;
Debug.DrawLine(endPos, Vector3.zero, new Color(0, 1, 0, 0.2f));
}
}
Answer by Bunny83 · Nov 04, 2016 at 12:09 PM
Well, it is the shortest path. Keep in mind that you rotate in 3 axes. If it would rotate along the red path the quaternion would be upside down. So it needs an additional 180° rotation around the local z axis. The used rotation only rotates 160 around y and 50 around x and z.
Keep in mind that quaternion represent an orientation, not just a direction. Vector3.Slerp would do what you want, but of course only for one axis.
thank you very much to let me know the Quaternion's real meaning.
vector3.Slerp() is worked.
Answer by jeffonsea · Nov 04, 2016 at 11:56 AM
Hi @pplasto.
What are you trying to do with the Quaternion.Slerp() method ?
I have the feeling there must be a much simpler way to adchieve a movement interpolation with a rotation interpolation.
which method? simpler way? i just want to get the shortest path of rotate
Your answer
Follow this Question
Related Questions
Opening door script in C# 3 Answers
Object rotation naturally change 0 Answers
[Solved] Smooth rotation with keydown 2 Answers
Rotating 2D Sprite 0 Answers
How to use Quaternion.Slerp with transform.LookAt? 3 Answers