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
0
Question by Bartol0ll0 · Aug 10, 2017 at 10:58 AM · rotationquaternionprecision

Weird rotation precision

Hi, I have script where I try to rotate my object to desired position, but the object doesnt have the exact angle I want, and its almost 1 degree of difference. I even wrote in script:

Quaternion _newRotation = connector.transform.parent.parent.localRotation;

_newRotation.y = 180;

connector.transform.parent.parent.localRotation = _newRotation;

But the rotation of object still isn't exact 180 alt text

I have never faced something like that. I know about floating point precision but most of the time its difference of about 0.00001 , not almost 0.7 How is that happening and how can I prevent this? Because of this I can't properly merge rooms for procedural dungeon generation alt text

transform.png (4.8 kB)
rooms.png (99.7 kB)
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 Bunny83 · Aug 10, 2017 at 02:12 PM

A Quaternion is a 4 dimensional complex number and do not represent euler angles.

You do not need to fully understand how quaternions work, but if you don't you shouldn't mess with it's 4 components. You can use Quaternions only by using the various static methods it provides.

You haven't presented how you actually create your rotation and how you define your "desired position".

You can create an absolute or relative rotation based on eulerangles by using Quaternion.Euler. Though in many cases you usually use things like Quaternion.LookRotation, Quaternion.AngleAxis or Quaternion.FromToRotation to create a rotation. For more details see the documentation

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 Glurth · Aug 10, 2017 at 09:43 PM 1
Share

So, rather than:

 Quaternion _newRotation = connector.transform.parent.parent.localRotation;
 _newRotation.y = 180; //this is the bad line- I suspect, you dont want to change the Y value of the quaternion you want to change the "rotatation about the Y axis" (one of the three euler angles).
 connector.transform.parent.parent.localRotation = _newRotation;

try this (uncompiled/untestest):

 Vector3 eulerAngles= connector.transform.parent.parent.localRotation.eulerAngles;//NOTE: the Vector3 usered here is not a "regular" Vector3 (direction, length), its simply a convient place to store three angles (in degrees)
 eulerAngle.y=180;// notice we are changing the Y value of a Vector3, not a quaternion.
 connector.transform.parent.parent.localRotation= Quaterion.Euler(eulerAngles);// creates a new Quaterion using these euler angles and assigns it to the localRotatation.


avatar image Bartol0ll0 · Aug 11, 2017 at 11:12 AM 0
Share

Yes guys, I made a huge mistake in which I used quaternions ins$$anonymous$$d of Vector3 representing euler angles. Thank you Bunny83 and Glurth!

avatar image
0

Answer by TGamingStudio · Aug 10, 2017 at 02:09 PM

probably it is Child with something . than it have some weird rotation .

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

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

93 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 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

Quaternion.ToAngleAxis is Unprecise? 1 Answer

2D character rotation wrong direction when moving 1 Answer

Simple Rotation 1 Answer

i have rotated an gameobject but the axis of the object did not change 2 Answers

make projectiles always hit target 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