Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TSI25 · Mar 14, 2017 at 07:31 PM · quaterniongyroscope

Amplify Gyro Input

So I'm getting a quaternion back from a gyroscope in my mobile device, and I'm using that to rotate an object in my game. What I'm trying to do is amplify the amount of rotation by some amount, so if the gyro is rotated 90 degrees clockwise, the object in game will actually rotate more like 120 degrees clockwise. Is there a recommended way to do this? Quaternion math is sort of a black box to me.

Comment
Add comment · Show 3
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 m0guz · Mar 15, 2017 at 01:43 PM 0
Share

You can get EulerAngle with Quaternion.eulerAngles Unity Docs - Quaternion.eulerAngles which returns Vector3 containing x,y,z rotations and use it for calculation.

avatar image TSI25 m0guz · Mar 15, 2017 at 04:42 PM 0
Share

How would I go about using it for calculation? I've tried things like this

 Quaternion quat = initRotation * RotateFromGyro();
             
             Vector3 rotationThisFrame = quat.eulerAngles;
             rotationThisFrame *= sensitivity;
             quat = Quaternion.Euler(rotationThisFrame.x, rotationThisFrame.y, rotationThisFrame.z);
 
             transform.rotation = quat;

which works if I assign quat directly to the transform.rotation without doing anything but doesn't work if I modify the rotation this frame

Edit: By doesnt work i mean the rotation gets really wonky, rotating in unanticipated axis at unanticipated speeds

avatar image hexagonius · Mar 15, 2017 at 06:35 PM 0
Share

I would read the acceleration values which go from -1 to 1. it's easier to convert that into a rotation with Quaternion.Euler(). and then just set it as the rotation for the object

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by lgarczyn · Mar 15, 2017 at 07:26 PM

DO NOT USE EULER ANGLES.

It's a terrible idea. Just don't do it. They can blow up in so many ways. As soon as you are doing rotation on more than 1 axis, Quaternions all the way.

There are tons of way to do this. If you simply want to double the rotation (moving 1 degree IRL moves 2 degree in game), just do:

 transform.localRotation = initRotation * rotateFromGyro * rotateFromGyro;

if you actually want a factor, just do

 transform.localRotation = initRotation * Quaternion.LerpUnclamped(Quaternion.identity, rotateFromGyro, ratio);

If the ratio is 0.5f, you'll get half the rotation, if it is 2f, you'll get twice the rotation. There might be unforeseen behaviors, but this should work.

Comment
Add comment · Show 7 · 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 TSI25 · Mar 15, 2017 at 07:31 PM 0
Share

you sir, win the accepted answer. Thanks this helps out a lot!

avatar image unity_3e8ufYsw8duDNA · Apr 13, 2018 at 11:46 AM 0
Share

Hi. I'm beginner with unity and actually finding the way to amplify the rotational value. I'm stuck on this issue. Can you please tell me; what is initRotation and RotateFromGyro() in: transform.localRotation = initRotation RotateFromGyro() RotateFromGyro(); waiting for the reply asap. Thank you!

avatar image lgarczyn unity_3e8ufYsw8duDNA · Apr 13, 2018 at 01:11 PM 1
Share

Hi, it's pretty simple, they are both private Quaternions of the script.

initRotation is the default rotation of your object:

  1. if your object is not rotated at all, you can set it to "Quaternion.identity", or remove it.

  2. if your object is rotated by, say (90,90,0), you can just set to Quaternion.Euler(90,90,0)"

  3. if you want the object to keep the rotation from the editor as default, set it to "transform.localRotation" on Start()

transformFromGyro is simply Input.gyro.attitude, but you can use another source , such as another gyro library, or the default C# interface.

avatar image unity_3e8ufYsw8duDNA lgarczyn · Apr 16, 2018 at 04:34 AM 0
Share

Thank you ceandros! Sorry for late reply. I need to increase the rotation speed of camera with the head rotation like if head is rotated 30 degrees then camera rotation must be rotated like 40 or 50 degrees. So the solution mentioned above would be suitable for this or not?

Show more comments

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

67 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

Related Questions

Gyroscope in Landscape mode snaps object to random rotation 0 Answers

Comparing quaternion values and extracting values from quaternions 0 Answers

Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 1 Answer

multiplying gyro output 0 Answers

How to get the value of the an angle of the Gyroscope? 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