Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by cmasterenko · Apr 26, 2011 at 02:26 AM · ipadaccelerometerlandscapeautorotate

Accelerometer Auto rotate Issue

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;
    }
}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Cyb3rManiak · Apr 26, 2011 at 09:21 AM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cmasterenko · Apr 27, 2011 at 06:42 AM 0
Share

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.

avatar image Cyb3rManiak · Apr 27, 2011 at 09:14 AM 0
Share

I can try and help you, but I think that without Unity for iPhone and working from memory alone without seeing some code it will be tricky. Have you tried looking at some example projects and see how other people deal with this issue? For example, http://unity3d.com/support/resources/tutorials/penelope is a ncie tutorial that might address this issue (As I said - I just don't remember... :/ ).

Any chance this is a silly thing like using transform.localPosition ins$$anonymous$$d of transform.position? Or using Transform.TransformDirection to get relative direction and not global direction?

avatar image cmasterenko · Apr 29, 2011 at 06:25 AM 0
Share

Penelope 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.

avatar image cmasterenko · Apr 29, 2011 at 06:44 AM 0
Share

Okay, 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?

avatar image
0

Answer by Cyb3rManiak · May 01, 2011 at 08:52 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

help setting up a boundary wall for android accelerometer 2 Answers

iPad touch scripting... 0 Answers

From Unity to Xcode.... 1 Answer

Detect ipad landscape right/left on startup then lock it. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges