- Home /
Weird movment/rotation with Quaternion.Lerp()
Hi guys, I am trying to interpolate am Camara between transforms. My cod for that is:
Camera.main.transform.position = Vector3.Slerp(_v3CamTransitionFrom, posTo, transitionProgress);
Camera.main.transform.rotation = Quaternion.Lerp(_quCamTransitionFrom, rotTo, transitionProgress);
Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 10, Color.cyan, 3);
And this is the result:
I need the camera to keep looking at the blue monkey as it does in the first and last frame of the movement. Why does it make this weird loop to the side? What did I miss or how could I get it right? If this Question already exists, I am sorry but I could not find it
Thank you in advance.
Here is suitable method (and example) to fix your issue https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
So use that instead of setting the rotation with Quaternion.Lerp
Answer by fungusamongus4 · Jul 12, 2021 at 02:15 PM
I suggest using Transform.LookAt method every frame of the transition instead.
Answer by Haissem55 · Jul 14, 2021 at 10:52 PM
With that the camera does a 180, if it goes over the the lookAt, so it does not work