Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by MSpiteri · Mar 17, 2016 at 10:31 AM · rotationeditorprecisionaccuracy

Unity editor rotation accuracy 89.999 etc

Have you ever noticed that there is a problem in the Unity Editor with the accuracy of the rotation of the objects? This happens to me many times when I duplicate objects. For example if an object has a rotation of 90 degrees in the y-axis, as soon as I duplicate that object, the rotation of the new object becomes 89.999.

This is not a problem as such, but it gets annoying. Has anyone found a fix for this?

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 Dave-Carlile · Mar 17, 2016 at 04:00 PM 3
Share

What Every Computer Scientist Should $$anonymous$$now about Floating-Point Arithmetic

Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. Although there are infinitely many integers, in most programs the result of integer computations can be stored in 32 bits. In contrast, given any fixed number of bits, most calculations with real numbers will produce quantities that cannot be exactly represented using that many bits. Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation.

avatar image Fredex8 · Mar 17, 2016 at 06:09 PM 0
Share

As I am a little bit OCD about accuracy things like this drive me insane, especially in 3D modelling software when I model to fractions of a millimetre and want things modelled perfectly.

It is annoying in Unity too as it makes comparing angles and positions awkward without rounding them or having a tolerance. One solution I sometimes use is to set the Euler Angles to remove inaccuracies that may have worked their way in there. Not ideal I'm sure but it seems to set values more accurately than other methods.

 example.transform.localEulerAngles = new Vector3(0, 90, 0);


avatar image MSpiteri Fredex8 · Mar 18, 2016 at 09:58 AM 0
Share

OCD :) Same here! This is why I posted this question. This thing also drives me nuts and I waste a lot of time going through the duplicated object to set its angle properly.

$$anonymous$$y worry is that if the angle is 89.999 and the axis movement is set to "Local", moving the object in the x-axis would eventually give a big error in the position of the object. So I would have to correct the position anyway.

I was thinking about making a $$anonymous$$enu script that, when executed, goes through all Transform objects of the scene and rounds up the angles to the nearest degree. I like to use round numbers for angles, so I guess this would be the best solution for me (and for us OCD people, hehe). :-)

avatar image Bunny83 Fredex8 · Mar 18, 2016 at 11:36 AM 0
Share

I also like things to be perfectly aligned, however certain things can't be done. Unity stores the rotation not in euler angles but as quaternion. That conversion can introduce small errors.

Just to be clear what that would mean:

If your angle is off by 0.000001 degrees the sine of that value would be 0.0000000174532925. So when moving sideways on the x axis say +- 10000 units the error on the z axis at 10000 units would be 0.000174532925 units so that's 0.17 "milli units". The floating point format only has around 6-8 significant digits, so when you're about 10000 units away from the center you only have about 3 digits behind the decimal point.

avatar image armorhide406 · Apr 22, 2017 at 02:33 AM 0
Share

Just type in 90 into the corresponding box. As others have mentioned, it's just an artifact of how Unity works. If it bothers your OCD (and it does me, but I don't have OCD) then you have to take the time to make it an integer

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Theli · Mar 17, 2016 at 03:22 PM

There is no "fix", it's just how floating numbers work. They are not precise by their definition.

In depth: You can actually have exactly 90 as floating number, like many other integer values. However under the hood unity doesn't use Euler angles for rotations, it uses quaternions. So, when you set rotation to 90 degrees it gets converted to quaternion. Quaternion consists of four small floating numbers (all of them are < 1), and these are not precise. So when editor converts them back into Euler angles to display to you small errors are inevitable.

Comment
Add comment · Show 2 · 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 Bunny83 · Mar 18, 2016 at 11:53 AM 0
Share

btw: The number doesn't "float", it's the decimal point that "floats" to the left or right. That's why they are called: floating point numbers.

And if you want to understand quaternions a bit better, i suggest this numberphile video.

avatar image MSpiteri Bunny83 · Mar 18, 2016 at 12:35 PM 0
Share

@Bunny83 ... Thanks for the video. Very instructive :)

avatar image
2

Answer by Kamil1064 · Mar 17, 2016 at 10:55 AM

@MSpiteri, That's normal behaviour and not only in unity, the same in blender, for example. But if you need to compare values and you don't want random working you may use:

  private float precise = 90;
     if(Mathf.Round(transform.rotation.z) == precise)
     // do you stuff

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 Eno-Khaon · Mar 17, 2016 at 03:53 PM 3
Share

Another option for number comparison for a case like this, especially, would be use to $$anonymous$$athf.Approximately. It's intended, by design, to act as the floating point equivalency comparison.

 if(transform.rotation.z == 90.0f)
     // Less reliable
 if($$anonymous$$athf.Approximately(transform.rotation.z, 90.0f))
     // $$anonymous$$ore reliable
avatar image elenzil Eno-Khaon · Mar 17, 2016 at 05:16 PM 0
Share

agreed. $$anonymous$$athf.Approximately() is a much better approach than going through $$anonymous$$athf.Round(), because with the round() approach everything from 89.5 through 90.4999 will be "equal to" 90. If you were working with radians ins$$anonymous$$d of degrees, the result would be disastrous because the rounding error would be equivalent to nearly 60 degrees! I$$anonymous$$O it's also easier to understand the intent of the code.

avatar image Black_Demon Eno-Khaon · Dec 06, 2016 at 05:44 PM 0
Share

Thanks, it's exactly what I was looking for.

avatar image
0

Answer by Matexyu · Mar 30, 2017 at 01:22 PM

By the way, it looks like this rounding error no longer manifests itself when copy-pasting GameObjects, at least here, using Unity 5.5.1f1.

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 tanoshimi · Mar 30, 2017 at 03:40 PM 0
Share

The way the editor displays the values may have changed, but I can assure you that the underlying data is no more (in)accurate.

If you wanted, you could write a custom inspector that rounded all rotations to the nearest whole integer prior to display in the editor, but the underlying backing value would still be a float, with all that entails.

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

61 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

Related Questions

How to specify the rotation angle in degrees, in the inspector? 2 Answers

Quaternion.ToAngleAxis is Unprecise? 1 Answer

Android Gyroscope inaccuracy problems. 1 Answer

More precise Vector3 2 Answers

Pivot vs center 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