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 zharik86 · Dec 12, 2013 at 05:37 PM · rotationtransformquaternioneulerangles

Problem in Euler angles

Good afternoon. I have the following problem. For object rotation I use Quaternion.Euler with value of the appropriate angles. As I understood in a number of experiments, in Unity there is a certain problem for angles of the close to 90 degrees in case of rotation on a y axis. For example, following code:

  void start() {
   this.transform.rotation = Quaternion.Euler(88, 0, 0);
   Debug.log("myangles=" + this.transform.eulerangles.x);
  }

In my debug, I see: "myangles=90". After several experiments, it is possible to tell with confidence that the such happens to value of an angle from 87 degrees. That is to 87 degrees value in logs matches what I set as Quaternion.Euler, but after 87 for some reason there is a rounding to 90 degrees. Prompt please, whether it is possible to make so that in Unity the correct values for the angles close to 90 degrees were put. (I sometimes need to rotate the camera to value 90, and then smoothly to transfer it to value 0 without involvement of the user)

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
1
Best Answer

Answer by robertbu · Dec 12, 2013 at 06:54 PM

The behavior is strange to me. Even though the Inspector reports 90, an object is clearly being rotated to 88 degrees. Regardless of this issue, it is a bad idea to read from eulerAngles if you can avoid it. There are situations where Unity changes the euler representation of the current physical rotation. So a work around would be to keep your own Vector3. Example:

 Vector3 myEuler;
 
 void Start() {
     myEuler = new Vector3(88,0,0);
     transform.eulerAngles = myEuler;
     Debug.Log("my X rotation: " + myEuler.x);
 }
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 zharik86 · Dec 13, 2013 at 07:02 AM 0
Share

I also tried such code, but the same result. There is a possibility of that I am a bug of the Unity version in which I work (version 4.1.2 and while I am not going to transfer to later). So this mismatch remains, but I try to avoid it in process of opportunities.

avatar image robertbu · Dec 13, 2013 at 07:07 AM 0
Share

Are you sure your code is not reading eulerAngles? This code works by treating eulerAngles as write-only and never reading the values back. The value in the inspector will still be 90 degrees, but your Debug.Log() and physical rotation will all be 88.0.

avatar image zharik86 · Dec 13, 2013 at 07:21 AM 0
Share

You are probably right, I applied such code yesterday and was guided by value in the Inspector, ins$$anonymous$$d of in logs. Then it turns out that value shown in the Inspector for this case not correct. Is it valid so?

avatar image robertbu · Dec 13, 2013 at 07:31 AM 0
Share

I ran the code and verified that the physical rotation is correct (i.e. only 88 degrees), and the angle reported from myEuler is also 88.0. The inspector will still report 90, but since you are not using eulerAngles, that won't impact your app.

avatar image zharik86 · Dec 13, 2013 at 07:48 AM 0
Share

I was guided by value in the Inspector, probably in it there was my error. Then I have a question: how to learn value of physical rotation? (how to receive these 88 degrees, without using additional variables? ) And many thanks for given help.

Show more comments
avatar image
1

Answer by TehJustice · Dec 12, 2013 at 07:30 PM

It's a known issue with conversion from Quaternion to euler angles. Just use the Quaternion rotation functions and you'll be fine.

transform.rotation = Quaternion.Euler(88, 0, 0);

will give you a rotation of 88.

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, 0), Time.time * speed);

will rotate you back to zero

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 zharik86 · Dec 13, 2013 at 07:12 AM 0
Share

Strange that it will turn on this angle (88), after all in the inspector it displays 90. And even in this case, to control my turning angle of the camera, it is necessary to enter float variable for this angle. Whether what in the Inspector it shows the wrong value is possible? For the help of the slerp function thanks, and that I used mathf.lerpangles for the angle necessary to me.

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

17 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

Related Questions

How do you smoothly transition/Lerp into a new rotation? 3 Answers

Camera viewport transformation from one world to the rotated world. 1 Answer

Working on a mini map 0 Answers

Rotation Jumping values (0 to 180) 1 Answer

How to get Angle float of specific axis.(Turret clamping related). 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