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 AhmadMujtaba · Jul 15, 2013 at 08:08 PM · rotationjavascripteulerangleseulerfloatingpoint

Euler Angle problem in If check

I am rotating my object by 90 degree over some time according to the following code.

thisTransform.RotateAround (thisTransform.position, degrees, 90*Time.deltaTime);

What I want to do is when the rotation of the object is (0,0,0), I want to do something (disable the script in the check). I print the euler angle in console and it shows (0,0,0). So according to the print value my if check must work.

euler = transform.eulerAngles; if(euler == Vector3(0.0,0.0,0.0) { //(perform something) }

Sometimes after performing rotation, the euler.x doesn't match the (0.0) check (I have divided my check to subchecks according to their x, y and z). When I saw in inspector against the "Rotation" values, the x value of the object is 1.001791e-05. At the same time the print statement shows it as 0.0 . I have attached the screenshot which shows my problem. As you can also see in console it misses the "XXXXXXXX" check because of the different value in inspector. Help me with the correct angle so I can perform my if check according to its (0,0,0) rotation. Thanks

alt text

euler.png (120.4 kB)
Comment
Add comment · Show 4
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 InfiniBuzz · Jul 15, 2013 at 08:08 PM 0
Share

see this question, or better it's first answer and the comment on it

avatar image AhmadMujtaba · Jul 15, 2013 at 09:05 PM 0
Share

I got it. then this is due to floating points. Is there a way I can convert these floating point to integer so I get the first part of the floating point excluding the part after the point. Something like this var integer : int = (int)floatingpoint; will this thing help me regarding my problem.

I have a confusion why the floating point is messing in this case (if that is whats happening). If I get the rotation of the current object it still gives me 0.0 while in inspector its 1.0000....

avatar image AhmadMujtaba · Jul 15, 2013 at 11:14 PM 0
Share

will try these two lines in the morning and will let you know if it works. Thanks anyways.

avatar image AhmadMujtaba · Jul 16, 2013 at 08:03 AM 0
Share

Thanks robertbu the following line helped me with my solution to what i was trying to do.

 if (Quaternion.Angle(transform.rotation, Quaternion.identity) < some_small_value) 

1 Reply

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

Answer by robertbu · Jul 15, 2013 at 09:15 PM

You can use Mathf.Round() to round a float to an int, but consider doing something like:

 if (Quaternion.Angle(transform.rotation, Quaternion.identity) < some_small_value) 

or

 if (Vector3.Angle(transform.forward, Vector3.forward) < some_small_value)
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

16 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

Related Questions

Store initial rotation in JavaScript 2 Answers

Trouble Spawning Bullets with proper rotation 0 Answers

Object makes random jumps in rotation 1 Answer

How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers

Trying to tween the rotation of a cube in x and z and having trouble 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