- Home /
iOS - Smooth auto-rotation of orientation
I would like to have auto-rotation of the device orientation feature on my game (a smooth rotation following the black corner frame, not a one frame flip). You can see this feature in safari and almost any other iOS application out there. But I can't find a way of doing it with Unity other than rotating the camera myself (which is a hacky of doing it though). The Keyboard object seem to rotate correctly but not the Unity viewport.
I've been looking on this site and unity forum but I can't find a direct answer for this question:
"Is there a way to let the device automatically take charge of the smooth rotation when orientation is changed OR do I need to manually rotate the camera ?"
If Unity doesn't provides that feature, is it possible in native Objective-C or Unity prevent this modifications ?
I'm sure a lot of people are looking for this exact same thing...
Thanks !
Mat
Answer by thomasw · Jul 28, 2011 at 01:14 AM
This is apparently a feature of 3.4, but I haven't figured out how to enable it yet. I've turned in on in the player settings, but it still doesn't appear to work.
Works great just enable inside the player under Resolution and Presentation the Auto Rotation option, Use Animated Autorotation and check the orientations you want. You have to create a build to see the results.
I had to activate it in code to get it to work properly (by setting Screen.orientation to ScreenOrientation.autoRotate and then setting Screen.autoRotateToPortrait, Screen.autoRotateToPortraitUpsideDown, Screen.autoRotateToLandscapeLeft and Screen.autoRotateToLandscapeRight to true as needed), but it does work very nicely from then on.
@TriplePAF I'm starting out with the OcclusionCulling sample http://unity3d.com/support/resources/example-projects/iphone-examples.html and setting those values, but the resulting project doesn't autorotate.
O$$anonymous$$. It appears that one of the existing scripts in the project was overriding the effect of the player settings. In the OcclusionCulling's iPhoneAnalogSticks.js script it sets
iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeLeft;
This appears to override the player settings and stops the view from autorotating. If you get rid of that line and set the project settings as @TriplePAF says it should work correctly. Thanks.
DISCLAI$$anonymous$$ER: Don't be too enthusiastic about this new feature, it is not really prefect atm. Please do read http://forum.unity3d.com/threads/98993-Unity-3.4-Portrait-Landscape-Autorotate-on-iOS-looks-bizarre