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 ratamorph · Jul 25, 2014 at 01:46 PM · rotationtransformquaternions

Getting the actual object rotation on just 1 axis

I'm trying extract the rotation in 1 axis of an object so I can combine it with another rotation.

The plan is to pass the rotation angle to Quaternion.AngleAxis to create the rotation quaternion in just that axis.

The issue is that the values on eulerAngles don't go from 0-360, they go from 0-90->90-0->360-270->270-360 in a clockwise direction. The other axis get flipped by 180 to make the rotation work. But I need a value that goes from 0-360 which is what works for Quaternion.AngleAxis.

This small code showcases the issue I'm having

 float angleX = transform.eulerAngles.x;
 Quaternion XRot = Quaternion.AngleAxis(angleX, Vector3.right);
 transform.rotation = XRot;

This code should just rotate the object in the x axis the same way it was already set, so shouldn't do much, but because of the way the angles are returned this is not the case. When the object goes past 90 degrees the rotation locks up and doesn't go any further.

I've looked for a solution to this issue for a while now and I can't seem to find any information on how to do this properly.

Comment
Add comment · 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 robertbu · Jul 25, 2014 at 02:38 PM 0
Share

Take a look at this answer for a plane HUD. $$anonymous$$ch is calculating the 'x' rotation.

http://answers.unity3d.com/questions/696271/how-create-modern-aircrafts-hud.html

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by ratamorph · Jul 26, 2014 at 07:55 PM

I fixed my issue, found a method to get the pitch, yaw, roll angles and created the following functions:

 public static Vector3 GetPitchYawRollRad(Quaternion rotation)
 {
      float roll = Mathf.Atan2(2*rotation.y*rotation.w - 2*rotation.x*rotation.z, 1 - 2*rotation.y*rotation.y - 2*rotation.z*rotation.z);
      float pitch = Mathf.Atan2(2*rotation.x*rotation.w - 2*rotation.y*rotation.z, 1 - 2*rotation.x*rotation.x - 2*rotation.z*rotation.z);
      float yaw = Mathf.Asin(2*rotation.x*rotation.y + 2*rotation.z*rotation.w);
                 
      return new Vector3(pitch, yaw, roll);
 }
             
 public static Vector3 GetPitchYawRollDeg(Quaternion rotation)
 {
      Vector3 radResult = GetPitchYawRollRad(rotation);
      return new Vector3(radResult.x * Mathf.Rad2Deg, radResult.y * Mathf.Rad2Deg, radResult.z * Mathf.Rad2Deg);
 }

Comment
Add comment · Show 3 · 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 SuppleTeets · Nov 26, 2015 at 06:43 AM 0
Share

Just what I needed to avoid flipping. Thanks!

avatar image ryevdokimov · Nov 24, 2016 at 05:37 AM 0
Share

Thank you, I've been looking for this for hours.

avatar image Datapax · Nov 24, 2016 at 06:24 AM 0
Share

You should accept your answer as correct. It helps others find the solution easier :)

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

25 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

Related Questions

Rigidbody spins out of control when colliding into corner 0 Answers

use quaternions in unity to rotate object. 1 Answer

Min-Angle Constraint Script Causes Jitter 0 Answers

How can I turn my cube object to the direction it is traveling? 1 Answer

Rotating a Vector direction by another Vector direction in one axis 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