• 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 Moeskjaer · Nov 25, 2014 at 01:06 PM · androidiosgyroscopegyro

Using Gyroscope with Android

Hi

I'm making a game that can be played with both iOS and Android devices and the gyrescope is an important part af that game. When a button is pushed I lock the current orientation of the device like this:

         // Lock gyro-coordinates
          gyrXLocked = Input.gyro.attitude.x;
          gyrYLocked = Input.gyro.attitude.y;
          gyrZLocked = Input.gyro.attitude.z;

Afterwards I have a light that lights up every time the device has this sepcific orientation (+/- a float value). It works perfect on iOS but on Android the light seems to light up kind of random and the orientation where the light lights up seems to be changing over time. Sometimes it seems to be affected by the physical position in the world and not the device orientation.

I have searched the web and found several posts saying gyroscope doesn't work on android. Though, these posts have been 2-3 years old so I would think a gyroscope would be implemented in most android devices by now!? Others have found a solution by using the accelerometer instead, but since I have to use a specific orientation that stays the same over time, that wouldn't work for me..

Does anyone know why the gyrescope is working differently on iOS and Andriod - and more importantly - does anyone have a solution to my problem?

Thanks

/Moeskjaer

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

Answer by tanoshimi · Nov 25, 2014 at 01:12 PM

I had this exact problem last year and wrote up a solution that worked for me at https://alastaira.wordpress.com/2013/08/24/the-7dfps-game-jam-augmented-reality-and-spectral-echoes/ (look for the heading Day 2: Accessing Sensor Data in Unity. A.K.A “Fun with Quaternions”).

Essentially, I had to create a parent gameobject rotated 90 degrees about Vector3.right, and then invert the z and w components of the gyroscope's attitude quaternion. Why? I have no idea. This was Unity 4.2, and worked on Android 4.1.2 on a Sony Xperia S and Android 4.3 on a Nexus 10 when using Landscape Left orientation.

Comment
kayy

People who like this

1 Show 0 · 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.

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

2 People are following this question.

avatar image avatar image

Related Questions

Power consumption because of compass and gyroscope on handheld devices 0 Answers

Jet Accelerometer Script 1 Answer

Gyroscope not working in Android Build, but it works on Unity Remote? 0 Answers

Is Gyroscope supported on all mobile Android iOS devices with a gyroscope? 3 Answers

Strange android gyrometer attitude angles 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