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 /
  • Help Room /
avatar image
0
Question by SuperSpasm · Sep 19, 2017 at 03:16 PM · transformtransform.rotationquaternionsrotationseuler angles

Euler Angles in code / inspector different (both local & global)

Hey, I've been banging my head against the wall on this for a good while now, googled a bunch with no results. hopefully you can help me.

The Problem

neither the global nor local euler angles for an object (in code), match the euler angles in the inspector. this makes it incredibly difficult to code logic that depends on rotation around a specific axis.


Testing

To test the problem, I reproduced it in neutral conditions,specifically:

  • used a new object with only one script: that logs the euler angles from code (found below)

  • object had identity position and scale

  • euler angles were not manipulated during playmode . they were set via the inspector once then compared to the Debug logs in playmode.


under these conditions, I still got funky discrepancies between the euler angles in the inspector and the code:

alt text alt text


I know that modifying euler angles directly is generally discouraged and could lead to gimbal lock, and that euler angle representations aren't unique. But I'd assume the inspector should be in sync with the code on this, otherwise it's massively confusing.


My Goal

What I was originally trying to do is rotate an object on the Z axis (between -45 and +45) from code, by adding torque and using a conditional on torque direction (if euler.z > 45 etc.)

The object I'm trying to rotate has euler (90,0,0) by default, and torque should only affect the Z angles

I'm open to alternatives on how to achieve this, but would like to understand what the hell is going on regardless.

Thanks!


Code for TestRotation:

 void Update ()
 {
     Debug.LogFormat("transform: GLOBAL euler: {0}\t LOCAL euler: {1} \n   rotation: GLOBAL euler: {2}\t LOCAL euler {3}",
         transform.eulerAngles, transform.localEulerAngles, transform.rotation.eulerAngles, transform.localRotation.eulerAngles);
 }


screenshot-14.png (150.2 kB)
eulerangles-discrepancy.png (146.6 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SuperSpasm · Sep 21, 2017 at 10:33 AM

So it looks like this only happens when euler angles are non-zero on more than one axis. if x,z=0 and I manipulate y only, euler angles are the same in code and in inspector (and behave predictably)

I'm still lost as to why thye're not the same otherwise- any ideas?

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

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

I cant find the issue on my code (Quaternion.Slerp) 1 Answer

Rotating transform more than 180 degrees 2 Answers

What is the difference between setting transform.eulerAngles and transform.rotation? 1 Answer

LocalRotation and Transform Rotate 1 Answer

What is the correct way to move objects relative to each other ? 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