Always rotate the camera to be stood close to upright.

Hi, I have a faux gravity system set up and the player can control a character collider around a sphere. The camera is attached to this and looks down onto the surface of the sphere (textured as the earth). The problem is that while the player can shift the position of the character controller up and down the surface as well as left and right (strafing), they can eventually lose the correct orientation.

For example, the camera could be looking at Italy on the sphere surface texture just fine but once the player has moved them around the planet, the boot-shaped Italy can become rotated.
A better example is Australia, after moving up past the north pole, the sphere has effectively started to flip upside down and upon reaching Australia, the view would show it flipped around.

I need to be able to keep the camera or character controller in the right orientation. Obviously, the character’s rotation and position are constantly changing when moving around the sphere, but I am wondering if there is a way to get the character to rotate to have the right ‘map’ orientation, i.e as with a compass needle always facing the north pole.

You could check the dot product of the camera.transform.up vector and Vector3.up. If the result is negative (= the angle in between the vectors is > 90) then flip the camera (rotate 180 degrees around transform.forward) so that it’s up vector is actually pointing upwards again.