I have a movement script that works pretty well when I'm playing on Landscape Left, but since I'm building for iPad, it needs to auto-rotate, so I put in a different script to do that, but when I try to make my movement script rotate with it, my objects still move in the opposite direction when playing on Landscape Right. I have my script below, it's probably just an oversight on my part, but I just can't figure it out.
function FixedUpdate()
{
var dir : Vector3 = Vector3.zero;
if(DeviceOrientation.LandscapeLeft)
{
dir.x = -Input.acceleration.y*.5;
transform.position.x += dir.x;
}
else if(DeviceOrientation.LandscapeRight)
{
dir.x = Input.acceleration.y*.5;
transform.position.x += dir.x;
}
}
2 Answers
2
Is there a chance that when you flip the device Input.acceleration gives you negative values, and you just cancel them out when you negate them because you expect to receive positive ones?...
Try and show the acceleration values on a GuiText on the screen to debug it better.
I'm afraid it was a long time ago I fiddled with iDevices and Unity and I'm a bit rusty.
See, this is what I mean I'm rusty... Can't believe I missed it.
You're not checking the current orientation in your IF clause...
DeviceOrientation.LandscapeLeft is an enum. It's like a constant value that you check against something. In your case:
Input.deviceOrientation
:)
if you print out the value of DeviceOrientation.PortraitUpsideDown, for example, you will always get the same value, and it will never change.
The important thing is which of these values is in Input.deviceOrientation at the moment, and it can only be one of the values in that enumeration.
Check the example in the link if it's confusing.
I've tried a lot of different variations of the movement for landscape right and displayed the output values, but no matter what I put, the output values always seem to be the same between landscape right and landscape left.
– anon48761692Penelope didn't have anything about auto rotation and transform.localPosition didn't really do anything, I suspect because my object has no parent. As for the Transform.TransformDirection, could you possibly elaborate on how to use that? I'm not quite sure and when I just tried to replace my transform with that, it gave me an error saying an instance of Transform is required to access TransformDirection. I really appreciate the help though, this is just driving me crazy because it works in one orientation but not the other.
– anon48761692Okay, I know what's wrong now, it never goes into my else if statement to check for if the orientation is landscape right. Does anyone know why this would happen or how to fix it?
– anon48761692Never found a solution about it either. Since these baked prefabs were in small quantities in my project, I now simply keep them as baked objects in the scene, and reposition them as I need. Looks like baked prefabs are unfortunately not available anymore ...
– micheldumais