Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 giantkilleroverunity3d · May 08, 2014 at 06:31 PM · transformquaternioneulerrotaion

How do I read the Transform's rotation value from the inspector's panel of a gameobject or transform?

I have this code:

 Debug.Log("MouseHalo Transform.Rotation vector x: " + target.rotation.x + "  y: " + target.rotation.y);
         var rotation = Quaternion.Euler(x, y, 0);
         transform.rotation = rotation;  // Rem this out to freeze
 Debug.Log("MouseHalo after setting Rotation vector x: " + transform.rotation.x + "  y: " + transform.rotation.y);

I am trying to set a gameobject's z axis in a certain direction but need to read what the x and y are currently?

The object's x axis stays 0.5, but the Y axis flips to 180.5.

Thanks.

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

2 Replies

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

Answer by DMGregory · May 08, 2014 at 07:56 PM

transform.rotation will give you a Quaternion representation of the rotation, so the x and y parameters don't directly correspond to the Rotation x and y fields of the Inspector. Very rarely does it make sense to read or manipulate a Quaternion's x/y/z/w parameters directly.

To get the Euler angles shown in the inspector, use Quaternion.eulerAngles:

 Vector3 eulerAngles = transform.rotation.eulerAngles;
 Debug.Log("transform.rotation angles x: " + eulerAngles.x + " y: " + eulerAngles.y + " z: " + eulerAngles.z); 

For the second part of your question, if you want to point the GameObject's z+ axis in a particular direction, the easiest way is:

 transform.rotation = Quaternion.LookRotation(zDirection);

You can optionally include a second parameter for the direction its y+ axis should try to point toward:

 transform.rotation = Quaternion.LookRotation(zDirection, yDirection);

Note that if zDirection and yDirection aren't perpendicular, the zDirection takes precedence - the resulting rotation will put the y+ axis as close as possible to yDirection, but not perfectly aligned. There are some tricks you can use to invert this behaviour, if you want the yDirection respected exactly and the zDirection as close as possible.

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 michelattin · Jul 31, 2018 at 01:36 PM

hey can i convert back eulers angle to quaternion?

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 blindbeats · Mar 23, 2021 at 08:50 PM 0
Share
 Quaternion myQuaternion;
 Vector3 euler;
 myQuaternion = Quaternion.Euler(euler);
 
 

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

NullReferenceException by localRotation And Quaternion.Euler!?? 1 Answer

What does a Vector3 state? 1 Answer

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

Problem with Quaternion.Euler() when rotating object 3 Answers

Pitch/yaw difference between 2 transforms 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