Roll by rotating camera past 360 degrees on x axis

The idea here is simple: I need to rotate the camera to provide the effect of rolling in first person. My major concern is that I want to rotate the camera on the x axis beyond 360 degrees. I am using Quaternion.Lerp for rotating.

//Inside the update function
EndAngle = Quaternion.Euler(5, 0, 0);
StartAngle = Quaternion.Euler(25,0,0);

if (tParam < 1)
{
  tParam += Time.deltaTime * lerpSpeed;
  Camera.main.transform.rotation = Quaternion.Lerp(StartAngle, EndAngle, tParam);
}

if (tParam >= 1)
{
  tParam = 0;
}

Here is working code I am using to rotate the camera from 25 to 5 degrees. Of course, I want to start at 5 and end at 365(5). I would however like the lerp to start at whatever the current rotation angle on the x axis is for the camera, but am wary that using StartAngle = Camera.main.transform.rotation.x will result in the StartAngle updating constantly. How should I go about taking the starting angle of the camera in an efficient manner?

tl;dr
How should I make the camera rotate to 365 degrees? (And should I use slerp to make the roll more realistic?) Thanks for any help in advance :slight_smile:

As you’ve found out, Quaternions are lazy…they always take the shortest distance path between two rotations. This means that you cannot do a rotation of more than 180 degrees with a single setup. One solutions is to use Vector3.Lerp() and assign the results to Transform.eulerAngles. There are two issues with using this method:

  1. Vector3.Lerp() does not handle the 360/0 boundary, so you have to change the representation of the values to something that will be incremented and decremented the way you want. So if you wanted to start at 25 and end at 5 the long way, you could specify the start as 25 and the end at 365. Or you could specify the start as -335 and the end as 5.
  2. You must never read Transform.eulerAngles. You need to maintain your own Vector3 representation of the angle and treat Transform.eulerAngles as write-only. If you were to read back transform.eulerAngles after setting it, you often find the internal representation different than the value you just set. As long as you only set eulerAngles, the rotation will work.