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
8
Question by DylanW · Oct 13, 2013 at 03:28 AM · c#

How to calculate transform.localEulerAngles.x as negative value?

I have an object at point 0,0 and when I moved my mouse to the left side of the screen to rotate the object, transform.localEulerAngles.x is display values such as 359, 358, and etc. I was hoping that it displays -1, -2, and so on.

Language: C#

Comment
Add comment · Show 3
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 TrickyHandz · Oct 13, 2013 at 03:53 AM 1
Share

All your angles will exist from 0 and 359 because this covers every degree in the rotation (circle). There are technically no negative values to be had. There is some nice background magic going on in the Unity editor with the transform display that allows the display of values like -90 in the inspector when really this is equivalent to 270.

avatar image DylanW · Oct 13, 2013 at 05:06 AM 0
Share

Hmm, I guess I have to work around this issue.

avatar image robertbu · Oct 13, 2013 at 06:50 AM 1
Share

Reading localEulerAngles can be tricky since a single physical rotation has multiple euler angle representations, and Unity may change the representation on you. First if you are doing your own rotation, then you can maintain your own Vector3 and never read localEulerAngles. If you maintain your own Vector3 in any format you want including axes that go from -180 to 180. Second, you can normalize any euler angle into -180 to 180.

1 Reply

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

Answer by Tomer-Barkan · Oct 13, 2013 at 05:51 AM

If you want to get the negative values for the left side, simply do the following calculations:

 float angle = transform.localEulerAngles.x;
 angle = (angle > 180) ? angle - 360 : angle;
Comment
Add comment · Show 8 · 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 DylanW · Oct 13, 2013 at 06:03 AM 1
Share

Wow. I cannot believe how easy that was. Thank you for providing the solution.

avatar image Tomer-Barkan · Oct 13, 2013 at 06:04 AM 4
Share

sure. Just note you'll jump from -179 to 180 at some point.

avatar image rodneynatura · Oct 13, 2015 at 11:31 AM 1
Share

Nice solution $$anonymous$$er Barkan, it saved me from getting late to work!

avatar image PanzerPotato · Jun 03, 2018 at 04:12 PM 0
Share

$$anonymous$$ore useful than anyone would ever know!

avatar image Hadid · Nov 05, 2018 at 07:52 AM 0
Share

Awesome Fix!

Show more comments

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

25 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Flip over an object (smooth transition) 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 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