EDIT: Sorry, I seem to have put this in the wrong place by accident – I’d move it if I could, probably belongs in the C# / Code section.
OK, here is some fairly simple code I wrote for a simulation game and tested in Unity 2020 – it seems mathematically correct and 100% worked in Unity 2020, but in Unity 2021 it no longer does. Now, the vertical angle seems to rotate around something dependent on the angle around Y, and not just rotating around the X as it should. Changing between rotation and localRotation does not make a difference (as it shouldn’t since the camera holder has no parent), not does getting the angle from Euler or AngleAxis. Again, it worked perfectly as expect in Unity 2020:
void AdjustHeading() {
float rotation = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;
headingAngle += rotation;
if(headingAngle > 360) headingAngle-= 360;
else if(headingAngle < 0) headingAngle += 360;
heading = Quaternion.Euler(0, headingAngle, 0);
}
void AdjustPitch() {
float rotation = Input.GetAxis("Vertical") * rotationSpeed * Time.deltaTime;
tiltAngle += rotation;
tiltAngle = Mathf.Clamp(tiltAngle, minPitch, maxPitch);
tilt = Quaternion.Euler(tiltAngle, 0, 0);
}
void SetRotation() {
angle = heading * tilt;
transform.rotation = angle;
}
Is this a bug or an intentional change? And what would I need to do to make it work correctly – rotating separately around the Y and X, as intended and as it did before? Why aren’t quaternions acting like quaternions anymore?!