Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by eruizr · Jul 08, 2016 at 06:24 PM · androidgyroscope

gyroscope enabled but not working on android device

Hello everyone,

I'm trying to have a camera wich rotates under control of the device gyroscope. After reading the documentation and some trials, I have written a script, attached to the camera, and it works pretty well when I enter play mode in my android device through Unity Remote 4. I can obtain the quaternions from the device and the camera rotates accordingly.

But the problem arises when I build the apk and then test it on my android device (Sony Xperia Z1). In that case, the gyroscope is enabled, but I can not get the readings from the gyroscope: the quaternion value of Input.gyro.attitude is always (0,0,0,0).

I tried a lot of things, but I can not find the problem. Please , can you help me?

Thank you very much in advance (and sorry for my english).

Here is the code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class rot : MonoBehaviour {
 
     Quaternion initialQuat;
     Quaternion attitudeFix;
     Quaternion attitudeRel;
     Text sondas;
 
     void Start () {
         Input.gyro.enabled = true;
         initialQuat = Input.gyro.attitude;
         sondas = GameObject.Find ("Sondas").GetComponent<Text> ();
 
     }
     
     void Update () {
         attitudeRel=Input.gyro.attitude*initialQuat;
         attitudeFix = new Quaternion (attitudeRel.x, -attitudeRel.z, attitudeRel.y, attitudeRel.w);
         transform.rotation = attitudeFix;
         sondas.text = "" + Input.gyro.enabled + attitudeFix;
     }
 
 }
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

6 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by eruizr · Oct 26, 2016 at 09:10 AM

Hi,

I don't know where was the problem exactly but now it is fixed. I did three things:

1) I updated to the last version of Unity.

2) Just after the initialization of the application I wrote:

Input.gyro.enabled = false;

Input.gyro.enabled = true;

3) I gave some time for the gyro of the device to start, so I wait 2 seconds before the first reading of the gyro.attitude.

Hope that this helps.

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 Wenger95 · Oct 26, 2016 at 10:24 AM 0
Share

Hi,

I tried but it still failed, I saw your question that your device is Sony, have you test it on Ios device?

I really have no idea it still return 0001. Anyway, thanks for the help.

avatar image eruizr Wenger95 · Oct 26, 2016 at 10:46 AM 0
Share

Hi again,

I have tested it on IOs devices and it works correctly. I am sorry that I could not help. I really don't know where was the problem in my case.

Regards

avatar image Wenger95 · Oct 26, 2016 at 12:24 PM 0
Share

When u test the iOS device, have add anything on Xcode? I add coremotion lib, but it's still not working.

avatar image Wenger95 · Oct 26, 2016 at 06:08 PM 0
Share

It's working now!!! I update to 5.5.0b9, and it works, my old version is 5.5.0b6. Thanks!!!!! Thank you!!!

avatar image
1

Answer by Wenger95 · Oct 24, 2016 at 08:02 PM

Hi, Have you sort this? I have same issue, my Input.gyro.attitude always return 0,0,0,1. And I found out Input.gyro.enabled = true; only work once, after start it become to false.

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
avatar image
0

Answer by Bruhpunzel · Nov 22, 2018 at 03:00 PM

On Awake I put;

Gyroscope m_Gyro;

 void Awake()
 {
     //Set up and enable the gyroscope (check your device has one)
     m_Gyro = Input.gyro;
     m_Gyro.enabled = true;
 }

void Update () { //transform.rotation = Input.gyro.attitude; Debug.Log(Input.gyro.attitude); Debug.Log(Input.isGyroAvailable); }

Reads and outputs fine for me now. Hope that helps!

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
avatar image
0

Answer by doq · Feb 03, 2019 at 06:15 AM

I was getting zero data from attitude when I initialized in Awake or Start sometimes. I solved the issue by putting the gyro initialization in a coroutine.

 void Start()
 {
     StartCoroutine(InitializeGyro());
 }
 
 IEnumerator InitializeGyro()
 {
     Input.gyro.enabled = true;
     yield return null;
     Debug.Log(Input.gyro.attitude); // attitude has data now
 }
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
avatar image
0

Answer by Musahan17 · Nov 02, 2020 at 10:03 AM

 private bool GyroEnabled() 
 {
     if (SystemInfo.supportsGyroscope)
     {
         gyro = Input.gyro;
         Input.gyro.enabled = true;
         return true;
     }

     return false;
 }

This kind of approach worked for me.

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
  • 1
  • 2
  • ›

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

97 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 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 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 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 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 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 avatar image

Related Questions

Gyroscope Samsung S7 doesn't work properly 4 Answers

Gravity on Android 1 Answer

Input.gyro seems not working on android 8.1 0 Answers

[Gyro] unexpected rotations and offset 2 Answers

Control Camera Rotation with Mobile Device Gyroscope 2 Answers


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