[QuaternionSlerp] Lookback script

Quaternion currentRotation = Quaternion.Euler(0, 0, 0);
Quaternion rotation = Quaternion.Euler(0, 140, 0);

		if(Input.GetKeyDown(KeyCode.P))
			theCamera.localRotation = Quaternion.Slerp(rotation, currentRotation, Time.deltaTime);

		if(Input.GetKeyUp(KeyCode.P))
			theCamera.localRotation = Quaternion.Slerp(currentRotation, rotation, Time.deltaTime);

Camera not slerping/lerping when i press “P” it will just rotate instantly.

1 Answer

1

try following:

if(Input.GetKeyDown(KeyCode.P))
    theCamera.localRotation = Quaternion.Slerp(theCamera.localRotation, currentRotation, Time.deltaTime);

if(Input.GetKeyUp(KeyCode.P))
     theCamera.localRotation = Quaternion.Slerp(theCamera.localRotation, rotation, Time.deltaTime);

Works great but the Camera.locaRotation.y is always changing