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 GameDev2012 · May 10, 2012 at 12:09 PM · rotationrotatecubeeuler

Object rotation to exact degrees not working

Hi all,

I have almost completed my project but have one major problem. I have a 3d cube that I am trying to set the rotation of at the beginning of the game. It will be a different face showing each time the level is loaded. The problem is that I keep getting strange numbers coming up for the x y z degrees.. Instead of it being 0 for x it sometimes comes up with something like -6.5587e or some strange minus figure! This also happens with y & z too, and is only occurs some of the time, but I do need the roation to be an exact multiple of 90 degrees, i.e 0, 90, 180 etc.

I am setting the rotation as in the code below:

// Chosen X Axis var FaceX : int = 0;

// Chosen Y Axis var FaceY : int = 90;

// Chosen Z Axis var FaceZ : int = 270;

Cube_1.transform.eulerAngles.x = FaceX; Cube_1.transform.eulerAngles.y = FaceY; Cube_1.transform.eulerAngles.z = FaceZ;

This does change the face showing correctly, but the inspector window sometimes shows these strange minus numbers instead of 0. I have also tried it as:

Cube_1.transform.eulerAngles = Vector3(FaceX, FaceY, FaceZ);

The same thing happens. Can anyone please suggest anything to solve this???

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · May 10, 2012 at 12:14 PM

The reason the euler angles need to be calculated is because Unity does not store rotation information that way internally. This is why they sometimes show strange numbers. It can also be attributed somewhat to floating-point error- these numbers you see are close enough to epsilon that they may as well be zero.

Why do you need the numbers to be so precise? Make sure that you're not asking for something that the game engine can't actually do, and be prepared to use reasonable approximations.

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 GameDev2012 · May 10, 2012 at 01:07 PM

Hi, thanks for your answer, that makes sense.

I have a set of 3d cubes all with different coloured faces. They rotate in groups of 3, so they can show a different face than the rest of the cubes. I need the numbers to be exact so that I can tell when all of the cubes are showing the same colour. I'm doing this based on their rotation vales for x y and z. Unless there is another way of being able to detect when all the cubes show the same face?? I'm a bit stuck. Any suggestions welcomed.

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 GameDev2012 · May 10, 2012 at 01:07 PM

Hi, thanks for your answer, that makes sense.

I have a board of 3d cubes with different coloured faces. They rotate in groups of 3, so a different coloured face may show from the rest of the board. I need the values to be exact so that I can tell when all of the cubes are showing the same colour. Is there any other way of detecting when all the cubes are showing the same colour to the user?? Or any other way of setting the rotation value to be exact? Any suggestions greatly welcomed.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

instant rotate an object 3 Answers

Camera rotation behaving strangely 2 Answers

Trying to tween the rotation of a cube in x and z and having trouble 2 Answers

How do I rotate a quaternion with euler angles? 0 Answers

Limiting rotation of object, specifically using scroll wheel 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