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
0
Question by felartu · Sep 04, 2014 at 09:18 AM · rotationeulerwp8

Having hard time working with rotations and gyro

Hi,

I need some help with rotations and quaternions:

I'm reading the Gyroscope of my mobile phone and the results I'm getting are not consistent with what is supposed to.

The X axis of Input.gyro.attitude is working good, I use Input.gyro.attitude.eulerAngles.x and 0 degrees is the north no matter how tilted the phone is. The problem is with the Y axis, that is supposed to be the tilt degrees, it varies the value if I move the X axis while keeping the same tilt.

I have been busy at this for days now and cannot find an explanation for this behavior.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by ulissescad · Jul 29, 2016 at 12:29 PM

Try this:

I used some examples of reply and unity to made this code, and him works fine to me:

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
Add comment · 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 moire76 · Sep 05, 2016 at 09:10 AM 0
Share

Works like charm, thank you!

avatar image Play_Edu · Mar 05, 2018 at 10:22 AM 0
Share

Thanks, its help a lot and working fine for me.

avatar image
1

Answer by nicomaque.jette · Mar 06, 2015 at 03:04 AM

It's an old thread however if someone bumps on this one, the following thread helped me out a lot: http://forum.unity3d.com/threads/gyroscope-quaternion-to-unity-camera-help-please.75288/

These simple commands made the tricks for me (unless the phone is flipped):

Camera.mainCamera.transform.rotation = gyroQuaternion;

Vector3 ea = gyroQuaternion.eulerAngles;

Camera.mainCamera.transform.eulerAngles = new Vector3( -ea[0], -ea[1], ea[2]);

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 GameVortex · Sep 04, 2014 at 09:52 AM

This is because it is the EulerAngles representation of the rotation Quaternion which does not obey a normal degree rotation and will not always be what you expect even though they are correct for the rotation. I suggest you read a little up on Quaternions and how they work.

As a test: Have you tried rotating an object in your scene to match the rotation of the gyroscope, just to see if the rotation is correct? Example: transform.rotation = Input.gyro.attitute;

Comment
Add comment · 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 felartu · Sep 04, 2014 at 12:47 PM 0
Share

I have attached the gyro.attitude to the main camera and works good.

If I use gyro.attitude.x (which is a quaternion X axis) it gives the same values as gyro.attitude.y when pointing west and east when tilting the phone, that's why I'm converting them to Euler because the reading is not what I expect in quaternions.

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

8 People are following this question.

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

Related Questions

Restricting GameObject Rotation 1 Answer

How can I multiply the rotation of a mirrored object? 1 Answer

How do you manually override mecanim's interpolation with rotations? 2 Answers

Rotate an object around z axis on user input 1 Answer

Object makes random jumps in rotation 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