I use mouse LeftButton to rotate camera. But when I run the program, I find that if Quaternion.Lerp(loaclRotation, newRotation, t) t !=1, the camera.transform.localRotation and parent.transform will not equal to xR and yR. After rotating, if clicked mouse leftbutton, camera will rotate a little angle.
I think the reason will be that when t < 1 , the final rotation not equal xR or yR.so when I clicked , it will execute Quaternion.Lerp again, until the camera.localRotation equal xR or yR.
I make the t value is 1, so the Camera localRotation will be equal to xR or yR.
Is there any other solution to solve this problem?
`
if ((mouseState == MouseState.None ||mouseState == MouseState.LeftMouseBtn) && mouseLeftDown) {
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
smoothMouseX = mouseX;
smoothMouseY = mouseY;
var x = smoothMouseX * xRSpeed * Time.deltaTime;
var y = smoothMouseY * yRSpeed * Time.deltaTime;
xR -= x ;
yR += y ;
//Debug.Log("xR:" + xR + "yR:" + yR);
xR = ClampValue(xR, -360, 360);
yR = ClampValue(yR, yRMin, yRMax);
var rotation_x = Quaternion.Euler(yR, 0, 0);
var rotation_y = Quaternion.Euler(0, xR, 0);
//camera's parent component rotate the Y
transform.localRotation = Quaternion.Lerp(transform.localRotation, rotation_y , 1f);
//camera transform rotate the X
camera.transform.localRotation = Quaternion.Lerp(camera.transform.localRotation, rotation_x, 1f);
`