- Home /
The question is answered, right answer was accepted
LookRotation Vector3 is Zero, Yet Slerp Still Rotates?
Vector3 vector3 = new Vector3 (0.0f, 0.0f, 0.0f);
Quaternion qTo = Quaternion.LookRotation (vector3);
transform.rotation = Quaternion.Slerp (transform.rotation, qTo, Time.deltaTime * turnspeed);
(See code above). If my LookRotation vector3 is zero in every axis, why does my this Slerp function I have here still rotate my character 90 degrees? I am just curious and honestly quite baffled. I can send screenshots if you need a visual representation of this.
Answer by ScaniX · Aug 21, 2016 at 09:49 PM
See https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html
You actually pass a forward vector into the method. Instead of crashing with your invalid vector, it seems to fall back to some default (probably Vector3(0, 0, 1)) and return that look direction instead. And that is the rotation you get.
If your character transform has a forward vector like Vector3(1, 0, 0) that would result in a rotation of 90° around the world y-axis.
Don't you get an error in the console? The documentation says: "Logs an error if the forward direction is zero."
Yes I do get a notification that says "Look rotation viewing vector is zero" in the console. Thank you for your response :) @ScaniX
Answer by LK84 · Aug 21, 2016 at 09:47 PM
Have a look at the definition of Quaternion.Slerp: "Spherically interpolates between a and b by t. The parameter t is clamped to the range [0, 1]."
So as long as your current transform.rotation is not equal to zero rotation (Im honestly not sure if you get Quaternion.identity from LookRotation(Vector3.zero)), Slerp will return a value between these two rotations.
Follow this Question
Related Questions
Slerp to make the right/left side face another object 2 Answers
What am I doing wrong with these rotations? 0 Answers
Turret rotation on one axis problems 2 Answers
Quaternion.Slerp with Quaternion.LookRotation causes unexpected results 1 Answer
Quaternion.LookRotation and Vector3.SmoothDamp Problems 1 Answer