• 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 /
This question was closed Nov 14, 2018 at 11:46 AM by TSCSimulation_AH for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by TSCSimulation_AH · Nov 09, 2018 at 03:20 PM · transformquaternionrotatearoundosc

Use a Quaternion as a float?

Hi,

I'm currently working on a project that takes the Quaternion values from a gyro in a Steam controller and converts them into rotation/movement data, but the solution is far from ideal.

I would like to use the transform.RotateAround function because it is perfect for what we need, but I currently can't use the data because it needs a float.

Code:

 transform.RotateAround(primary.transform.position, new Vector3(0, Quaternion.Euler(0, tscZ, 0), 0), speed * Time.deltaTime);

tscZ is a Quaternion that takes the four values being sent over by the plugin UniOSC.

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

1 Reply

  • Sort: 
avatar image
4

Answer by JVene · Nov 09, 2018 at 06:16 PM

I must make a few assumptions to answer. First, your post doesn't include the quaternion from the gyro, but I think it a safe assumption that the eulerAngles property of that quaternion provides appropriate information.


The 3rd parameter of transform.RotateAround takes an angle in degrees. There are two situations I can infer from your description, and only you can choose which works. First, you may need to instantaneously align the transform to the value given by the gyro. The second is that you may want to gradually move toward the value given by the gyro (animating the move). Only in the second approach do you use the "Time.deltaTime" value to perform that animation, but not likely the way you've given in your post.


Further, I must assume that the axis created in your example is the axis of interest, and is also the axis from which you take data from the gyro (the Y axis, as it appears). If that assumption is correct, then you want the "y" rotation from the gyro's eulerAngles property as the angle you require. Note, however, that the orientation of this value may not be exactly as you expect. It could be the direction of a positive change in the angle is counterclockwise, while you might expect it to be clockwise (as if the gyro is mounted upside down). You must correct for that. Next, gyro's typically can't provide absolute positions. They're not compasses. They provide, instead, a relative rotation in a particular sample. I have no idea what your incoming data actually represents, but depending on how "raw" the data coming from the software interface to your gyro, that value may require a "perspective adjustment", like, perhaps, inverting the direction of the rotation, or "where is noon" (or where is zero - alignment).


Given that, the third parameter comes from something like gyro.Rotation.eulerAngles.y. That's the basics of this. The rest is a matter of refinement for your particular intention, which I can't divine from this information.

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

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

123 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 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

Ball Rolling Animation Not Working Properly 0 Answers

Get the rotation of a object around a arbitrary axis. 0 Answers

How to make Y-Axis face away from a position? 2 Answers

Write a C# script to record GameObject rotation? 4 Answers

transform.RotateAround problems 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