• 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
Question by humming_sc · Oct 24, 2013 at 10:43 AM · gyroscopecrossplatformgyro

Gyro difference between iOS , Android

I made some game using Gyroscope in both iOS and Android. I used Attitude in Gyroscope. But its results are too different.

 var offsetRotation : Quaternion = Quaternion.Inverse(originAttitude) * curentAttitude;
 var offsetRotationEulerAngles : Vector3 = offsetRotation.eulerAngles;

Are there some difference in Gyro between iOS and Android?

Sorry for my weak English.

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by tanoshimi · Oct 24, 2013 at 12:12 PM

I created a game using the gyro in Android and came across a ton of issues and inconsistent documentation about getting correct values. Conflicting advice I found included...:

  • Rotate the gyro attitude reading by a constant quaternion (0,0,1,0) and rotate its parent object by a constant angle of (90,180,0) for all device orientations (Post from “Aroha” in http://forum.unity3d.com/threads/98828-sharing-gyroscope-controlled-camera-on-iPhone-4/page5)

  • Rotate the gyro attitude by eulerangles (90, 0, 90) (Post by “George Foot” in http://forum.unity3d.com/threads/128493-Match-Unity-camera-with-iPhone-camera)

  • Rotate the gyro attitude dependent on screen orientation – Z rotation of –90 for Landscape Left, +90 for Landscape Right, or 180 for Portrait Upside Down, and also invert the z and w coordinates of the attitude quaternion to be (x, y, -z, -w) (http://blog.heyworks.com/how-to-write-gyroscope-controller-with-unity3d/)

In the end, I found that what worked for me on Android (tested on Nexus 10 and Sony Xperia S) was to invert the z and w values of the gyro attitude:

 attitudeFix = new Quaternion(gyro.attitude.x, gyro.attitude.y, -gyro.attitude.z, -gyro.attitude.w);

Note that this only worked when the device was in Landscape Left mode (which was the only orientation I was trying to support). No idea whether this works on iOS as I don't have a device to test, but I suspect you may need to adjust it. If you do find different values that work for iOS gyro, remember that you can add conditional preprocessor code to adjust depending on platform:

  #if UNITY_IPHONE
     ...
   #endif
  #if UNITY_ANDROID
     ...
   #endif
Comment
TangoDelta
Dragate

People who like this

2 Show 1 · 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 Mogart · Sep 02, 2014 at 09:57 PM 0
Share

Thank you a lot ! You saved my time. Works perfect

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Android] How do you set gyro start orientation 0 Answers

Input.gyro.attitude returns zero value 2 Answers

How add gyroscope to UnityRemote for iPhone? 1 Answer

I would like to know if with a unity free is possible to use gyroscope android? 1 Answer

UNITY 3D - Set the start positon of the gyroscope to initial phone position 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