- Home /
Quaternion Slerp is making me mad
Quaternion initial = Quaternion(90f, 180f, 0f, 1f); Quaternion ending = Quaternion(90f, 263.3441f, 0f, 1f);
float cameraPos = Mathf.SmoothStep(0.0f, 1.0f, (Time.time - startTime) / someTime);
cardCamera.transform.rotation = Quaternion.Slerp(initial,ending, cameraPos);
This will not rotate my camera. It is supposed to rotate my camera smoothly over a period of time from a starting to ending rotation, but it just snaps the camera to a strange rotation. The only thing I can think of is the construction of the Quaternion is done in degrees. It's been years since I've mess with this stuff so please assume I have the grasp of an infant.
Answer by DaveA · Jan 13, 2011 at 11:56 PM
Quats are x,y,z,w, where x,y,z define an 'axis' and w is related to the angle around that axis. That axis should also be normalized, so none of those numbers should be greater than one. Look at this reference to see what you can find: http://unity3d.com/support/documentation/ScriptReference/Quaternion.html
But you may want to instead use RotateTowards() on your camera.
The only reason I'm not using RotateTowards() is because I'm currently using a Lerp() to move the camera, so I really wanted to be able to use the same 0 - 1 variable to interpolate.
float cameraPos = $$anonymous$$athf.SmoothStep(0.0f, 1.0f, (Time.time - startTime) / someTime);
Answer by Jesse Anders · Jan 14, 2011 at 12:09 AM
To elaborate a bit, you don't want to construct quaternions manually that way, and the elements are not angles. DaveA is close with his description, except that the x, y, and z elements, while being parallel to the (unit-length) axis of rotation, won't necessarily be unit length. (The quaternion itself, however, will be unit length.)
If you want to create a quaternion from a set of Euler angles, however, you can write:
Quaternion initial = Quaternion.Euler(90f, 180f, 0f);
Quaternion [] cameraRotation = { new Quaternion.Euler(90f, 180f, 0f), //DEFAULT }
This is giving me an error. It says the nested type 'Euler' does not exist in the type 'UnityEngine.Quaternion'
Any idea?