- Home /
Quaternion lerp is not rotating my object to the desired rotation?
I have an object that I am trying to rotate to a certain rotation. The rotation I want is (0,0,90) that is based n the inspector when I try it manually.
DieRotations[0] = new Vector3(-90,0,180);
DieRotations[1] = new Vector3(180,0,90);
DieRotations[2] = new Vector3(180,180,0);
DieRotations[3] = new Vector3(90,0,0);
DieRotations[4] = new Vector3(0,0,90);
DieRotations[5] = new Vector3(0,0,0);
so I tried to this in my Update () method:
float speed = 0.01f;
Quaternion localRotation = gameObject.transform.localRotation;
Quaternion rotationTo = new Quaternion(DieRotations[4].x,DieRotations[4].y,DieRotations[4].z,0);
localRotation = Quaternion.Lerp(localRotation,rotationTo,speed*Time.deltaTime);
gameObject.transform.localRotation = localRotation;
This will work for certain angles, but in some cases it doesn't work. for example in this case it keeps going (as seen in inspector window) to (0,0,180)...
Any idea what I am doing wrong here? or why this is happening?
Thanks
Answer by iwaldrop · Jul 01, 2013 at 06:03 PM
It's probably because you're building your quaternion manually. Quaternion x,y,z is not what you probably think (unless you really understand quaternions). If you're trying to build a Quaternion from a Vector3 you should use Quaternion.Euler
public Quaternion rotation = Quaternion.Euler(new Vector3(0, 30, 0));
Thanks, that fixed it, yeah I don't understand quaternions...so is the rotation we see in the inspector window, is that the Euler angles of the object or the localRotation ?
Your answer
Follow this Question
Related Questions
Clamped Turret Doesn't Want to Lerp the Other Way 2 Answers
Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers
How can I pitch and roll a circular platform without releasing vertical/horizontal input? 1 Answer
Code to rotate around a local axis until local Y is 0? 0 Answers