Inverted Camera controls when flipped

Hello, thank you very much for any help you can provide. It is

I’m using a script called MouseLook. It’s very similar to MouseOrbit, that comes with Standard Assets. I attach MouseLook to my camera and set the Ymin to -360 and the Ymax to 360. My target object is a sphere. This now enables me to rotate infinitely in any direction around the sphere. All good so far.

The problem I’m having is when the camera flips upside down, my ‘Left/Right’ controls become inverted. I want to fix the controls so that they are always consistent visually.

My guess is the logic should be something along the lines of, “If camera is upside down: invert Left/Right controls”, and that should cancel out the effect this is having. Unfortunately my scripting/math skills are very beginner.

It seems that when the main cameras’ “transform.rotation.eulerangles.z == 180”, the camera is upside down and the control are inverted. I have no idea what’s going on with the quaternions here though. Any ideas on how to fix this?

Here’s where I’m at:

void Update ()
	{
		zRotation = GameObject.Find("Main Camera").transform.rotation.eulerAngles.z;
		
		if (axes == RotationAxes.MouseXAndY)
		{
			//if camera is upsidedown zRotation = 180
			// this first block is where i need to invert the invertedness, so to speak
			if (zRotation == 180){
				
			// Read the mouse input axis
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
			
			transform.localRotation = originalRotation * xQuaternion * yQuaternion;
			}
			else{
			
			// Read the mouse input axis
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
			
			transform.localRotation = originalRotation * xQuaternion * yQuaternion;
			
			}

I’m suprised no one has answered this. I’m finally on this problem right now I should have something soon for you.

having same issue… I tried inverting controls when reaching upside down but during inversion there’s some jitter / lag which kill the smoothness

ok so none got an answer?

1 Like