Hey all, for some reason I can’t quite solve this one, although I feel like I’m finally starting to understand quaternions pretty well.
I’m controlling a turret, and I rotate the turret directly through mouse input thusly (x axis code is a copy of the below, but obviously with x’s):
float rotationYInput = Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
Quaternion yQuaternion = Quaternion.AngleAxis(rotationYInput, -Vector3.right);
this.transform.localRotation = this.transform.localRotation * yQuaternion;
Now, I want to make this feel more mechanical and have the movement ability restricted, so it’s not just based on mouse-sensitivity. Something closer to the player using controls on an actual machine. So I switched to lerping the rotation like this:
float rotationYInput = Input.GetAxis("Mouse Y") * sensitivityY * Time.deltaTime;
Quaternion yQuaternion = Quaternion.AngleAxis(rotationYInput, -Vector3.right);
this.transform.localRotation = Quaternion.Lerp(this.transform.localRotation, yQuaternion, turnSpeed);
Close but no cigar - it’s using the Y-Input as the target, so it always goes back to forward after I fight to move it away from forward :). I know what’s going wrong, but I’m having a hard time figuring out the fix with quats. I need to take the input quat (yQuaternion) and add that to the localRotation, with is what I thought I was doing in the Lerp. Ideas?