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
1
Question by sysameca · Aug 11, 2014 at 10:20 AM · axisanglequaternions

Getting each axis angle from a game object

Is there a way to find out what is the angle of each and every single axis of a game object(transform.up,transform.right,transform.forward) and then reconstruct it with Quaternion.AngleAxis()?I see that there is a transform.ToAngleAxis(), but it seems that it converts the whole rotation to angle axis representation and i need each individual axis angle.

Comment
Add comment · Show 5
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 jamesflowerdew · Aug 11, 2014 at 10:52 AM 0
Share

I may be wrong but you could try this along the different axes. look rotation use the normals from transform.right,up etc. again this might not work, but it would be my first port of call.

avatar image Johat · Aug 11, 2014 at 11:58 AM 0
Share

I'm not 100% certain why you would need this but, if I understand your question correctly, you want to split the rotation into its 3 component steps?

The trouble with saying "what is the angle of each and every single axis of a game object" is that the "angle" doesn't really make a lot of sense without an axis to go round, so it becomes a little ambiguous.

The Euler Angles (transform.eulerAngles or transform.localEulerAngles -- the numbers shown in the inspector) is a Vector3 representing an angle of rotation about each axis. For example, transform.eulerAngles = new Vector3(45f, 0f, 0f); is a rotation of 45 degrees around the x-axis (right). So these may be the angles you want.

However, be aware that order matters in rotations. Rotating about x then about y, will give you a different outcome than if you rotated about y then about x so watch out! You should also avoid using Euler Angles directly too much since they run into problems that Quaternions don't have (Unity does everything in quaternions internally anyway).

Another solution, if you're treating it as a step-by-step rotation, could be to use Quaternion.FromToRotation(Vector3 fromDirection, Vector3 toDirection), and split it up that way, recording the quaternion of each step.

Could you perhaps give a bit more detail on why you want to do this and what you want to achieve? It will make it easier to give a relevant solution.

Thanks =).

avatar image Johat · Aug 11, 2014 at 12:04 PM 0
Share

For an example of the last method, if you wanted to know the rotation from Vector3.right to transform.right (and so on), you could do:

 Quaternion rotatedRight = Quaternion.FromToRotation(Vector3.right, transform.right);
 Quaternion rotatedUp = Quaternion.FromToRotation(Vector3.up, transform.up);
 Quaternion rotatedForward = Quaternion.FromToRotation(Vector3.forward, transform.forward);

Then each of those quaternions could be converted to an angle axis using Quaternion.ToAngleAxis(). However, you can likely just use them as they are (the angles are mostly there just to help us get our heads around things, everything done with quaternions at the end of the day).

avatar image sysameca · Aug 11, 2014 at 12:42 PM 0
Share

Euler angles gives the angle of the current rotation yes, but i was wondering can i get this angle and construct it with Quaternion.AngleAxis().Ill spare the details because i am doing an overall tests with rotations, nothing serious.

avatar image robertbu · Aug 11, 2014 at 04:36 PM 1
Share

If you take a look at this answer:

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

You can see code where I've deconstructed heading, pitch, and roll from the forward, up, and right of an object. It works fine for a plane HUD, but I suspect a bit more would need to be done to have a general solution.

Note in your test, while not related to the direction vectors, you can construct rotations based on eulerAngles. Given that 'v' is a Vector3 representing eulerAngles, you can construct that same rotation by:

 rotation = Quaternion.AngleAxis(v.y, Vector3.up) * Quaternion.AngleAxis(v.x, Vector3.right) * Quaternion.AngleAxis(v.z, Vector3.forward);

Note that you must compose the rotations in the order specified here. Change the order that the Quaternions are composed, and the rotation of the eulerAngles will not match the physical rotation of the objdct.

0 Replies

· Add your reply
  • Sort: 

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

23 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

Related Questions

Set angle of object around arbitrary axis by slider? 1 Answer

Vector3.Angle, set range on individual axis 0 Answers

limiting rotation to solid angle 5 Answers

Move and Rotate on a fixed axis? 1 Answer

How to rotate object based on another 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