- Home /
How to have a scene rotate with the device orientation
Hi all. I'm currently working on a side-scrolling game where the user swaps between two characters by rotating their Android device 180 degrees. I have achieved this to the extent that when the phone is rotated, the first character and camera are suspended, and the second character and camera are activated.
However, although the second character is then controllable, the orientation of the scene does not rotate with the device. In other words, the scene appears upside-down because it hasn't followed the device orientation.
The auto-rotation feature was not working so I manually coded the rotation based on the x-axis acceleration input, which works fine. But does anyone know how I can get the scene to follow this so as not to be upside-down?
Have you tried this?
https://docs.unity3d.com/Documentation/ScriptReference/ScreenOrientation.AutoRotation.html
In Player Settings you should set Default Orientation to Auto Rotation and check both landscape options.
Thanks for the reply. Yes, I read through that, but without a lot of luck. I established the following in my code:
IF Input.Acceleration.x is > 0.9, the device is held horizontally to the right.
IF Input.Acceleration.x < -0.9 the device is held horizontally to the left.
For each of these, I have then asserted the appropriate Screen.orientation = ScreenOrientation.LandscapeLeft or LandscapeRight. But where this should only require a 180 degree rotation, it seems that I actually have to rotate by 270 degrees (to a portrait orientation) before it will switch between characters.