• 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 thesanketkale · Dec 13, 2016 at 03:14 AM · androidgyroscopegyroreturn valuezero

Input.gyro.attitude returns zero values when tested with Moto G 4th generation device

Hi, being fairly new to unity, am using unity 5.4.0f3. I am working on a project which makes use of device gyroscope, if it exists, to give rotation to the main camera. I have tested the application on few devices, out of which Moto G 4th generation phone is the one, that I came across as of now, which even if has a gyroscope on it, gives zero values for Input.gyro.attitude. It is a device with 6.0.1 android and as mentioned 'https://issuetracker.unity3d.com/issues/input-dot-gyro-dot-attitude-doesnt-output-data-from-orientationsensor', there was one bug reported in unity about issues with getting gyro attitude values in newer devices(Android 6 or later)

I tried below code to debug the gyro values in phones:

using UnityEngine; using System.Collections;

public class gyro : MonoBehaviour {

  Gyroscope gyr;
 
  // Use this for initialization
  void Start () {
      gyr = Input.gyro;
      if (SystemInfo.supportsGyroscope)
      {
          gyr.enabled = true;
          Debug.LogWarning("Gyro Enabled");
      }     
  }
  
  // Update is called once per frame
  void Update () {
      Debug.Log(gyr.attitude);
  }

}

Is the issue really solved or am I doing anything wrong here? Is there a workaround that I should be looking at for newer devices like this? Any help or suggestion would be great.

Comment

People who like this

0 Show 1
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 moorjaniharesh · Dec 20, 2016 at 08:56 AM 0
Share

Hi, I am facing the same issue. Could anyone please help us out here?

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by anaeronbaggins · May 09, 2018 at 06:01 AM

@sanketkale The Moto 4th generation phones and lower generation(i am not that sure about the lower gen phones, but sure about the 4th gens, since I have a moto G4 plus) do not have a compass or magnetometer, which is what Input.gyro.attitude uses. If you want to use the gyroscope for AR, you need the compass/magnetometer, else the accelerometer will have to do. There are some obvious trade-offs between the gyroscope and the accelerometer, but then, it's a necessity. @yuk27 how did the code work if the phone doesn't have a compass/magnetometer? Do let me know, i would love to know. :)

Thanks! :D, sorry if the answer is wrong or something, i just posted my own experience. If someone has a change, do let me know, bye <3

Comment
thesanketkale

People who like this

1 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 thesanketkale · May 09, 2018 at 11:05 AM 0
Share

Yes, MotoG 4th generation phones lack magnetometer and gyro.attitude uses magnetometer's values in conjunction with gyroscope's values for giving a directional orientation quaternion. I have confirmed this with people from unity back in 2017. So, @yuk27, this is not a bug with unity, it's just how gyro.attitude works. And yes, your code could be used to get a directionless orientation quaternion from rotationRateUnbiased which takes values from just gyroscope sensor. So if you just want to rotate main camera based on phone's orientation irrespective of what direction the phone is from magnetic north, then you should go for gyro.rotationRateUnbiased. Well anyways, thanks for the answer @anaeronbaggins.

avatar image

Answer by yuk27 · Jan 25, 2017 at 08:15 PM

For anybody having this problem, I face it for a long time, in theory this problem was a bug on Unity that was resolved:

https://issuetracker.unity3d.com/issues/input-dot-gyro-dot-attitude-doesnt-output-data-from-orientationsensor

But even after that, the problem with gyro.attitude continued.

I found this thread that was really helpfull for me:

https://forum.unity3d.com/threads/gyroscope-quaternion-to-unity-camera-help-please.75288/

Where I found this code (Created by ulissescad):

 float yRotation;
 float xRotation;
 void Start{
 
 Input.gyro.enabled = true;
 }
 void Update{
 yRotation += -Input.gyro.rotationRateUnbiased.y;
 xRotation += -Input.gyro.rotationRateUnbiased.x;
 
 transform.eulerAngles = new Vector3(xRotation, yRotation, 0);
 }

Comment

People who like this

0 Show 2 · 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 JavierHerrera · Sep 15, 2017 at 02:33 AM 0
Share

(Moto G4 plus) It kind of Worked, Should it be tweaked? Because when I run it, Say I make a 360 degree Turn, On the game I check Half a turn (Not exactly half) PLEASE Ive been so many hours trying to make it work

avatar image JDavidL · Jan 15, 2019 at 12:32 AM 0
Share

thank you! that was really helpfull!

avatar image

Answer by unity_393CC71ED135A28145A7 · Nov 05, 2022 at 08:41 AM

Are you sure you enabled the gyro?

 Input.gyro.enabled = true;
 



Comment

People who like this

0 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

10 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

Related Questions

How should I interpret the gyro's information? 0 Answers

Input.gyro.attitude not working on newer Android devices 3 Answers

Using Gyroscope with Android 1 Answer

Gyroscope not working in Android Build, but it works on Unity Remote? 0 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