This problem is easily replicated in a 2D scene (camera facing down the Z axis) with a single 3D object, such as a cube. The object must have a rigidbody, and the following script:
using UnityEngine;
public class CubeMovement : MonoBehaviour
{
private Rigidbody body;
private float currentTurningRate = 0;
private float targetTilt;
void Start()
{
body = GetComponent<Rigidbody>();
}
void Update()
{
currentTurningRate = Input.GetAxis("Turn");
body.transform.Rotate(Vector3.forward * -currentTurningRate, Space.World);
targetTilt = body.transform.localRotation.eulerAngles.y - currentTurningRate * 10;
body.transform.Rotate(Vector3.up * targetTilt, Space.Self);
}
}
When the user presses left or right, the object should spin around the Z axis relative to the global space, and tilt slightly along the Y axis relative to its own space.
So what’s happening is that when the cube is rotated along the Z axis (Vector3.forward) between certain angles spanning about 180°, the next Rotate command causes it to spin like crazy around the Y axis (Vector3.up). When rotation leaves that range, the object responds as expected, where it looks like it tilts a little as it turns.
As you can see, I’ve pared the code right back and I’m still having the problem so I’m putting it down to me not quite getting how Rotate affects euler angles. Any ideas? Cheers!