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 itisieric · Apr 07, 2020 at 11:25 PM · quaternioninspectoreuleranglesangles

localEulerAngles.x changes when the angle is close to -90 in the inspector

I need to read the angle of the knee joint but the problem is the (eulerAngX) value is not a linear relationship with the X angle in the inspector? I think the (eulerAngX) will change depending on how close it is to -90 in the inspector. (see the two attached pictures) I need to read the angle of the knee joint to use in a robotic application you can see the YouTube video here to understand why I need to know the angle https://www.youtube.com/watch?v=odWTkAmW1LA&t=5s

I can't seem to get my little brain to figure this problem out. Thanks in advance for your help.

public class HelpMe : MonoBehaviour { public float eulerAngX;

 // Update is called once per frame
 void Update()
 {
     eulerAngX = transform.localEulerAngles.x;

     Debug.Log(eulerAngX);
 }

first.jpg (284.5 kB)
start.jpg (85.0 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
0

Answer by Bunny83 · Apr 08, 2020 at 04:51 AM

Well this issue has several aspects to it. First of all when the x rotation of the eulerangles reaches +-90° they are in a gimbal lock position and you loose one degree of freedom. This is an inherent problem of euler angles in general. The next problem is that euler angles are not unique. There are always more than one way to represent the same orientation. For example (45, 0, 0) is the same rotation as (180, 180, 135). Finally Unity does not work with euler angles but uses unit quaterions. Quaternions do not suffer from gimbal lock and allow a smooth transition between any two orientations. When you read eulerAngles / localEulerAngles Unity actually calculates the 3 angles from the quaternion representation. Since euler angles are not unique you can't be sure which one you get depending on the actual orientation.


For example in the gimbal lock orientation you loose one degree of freedom. For example if you rotate an object to (90,0,0) your object points straight up. If you want to rotate the object now to the left or right side (world z axis) there is no gimbal that allows this motion. In order to solve that issue the y and z angle would have to change immediately by 90° to provide the proper rotation axis.


If you have difficulties understanding gimbal lock, this video does a decent job explaining the issue in general.


To get the angle between two limb parts I would recommend to use the two direction vectors of your joints and just use Vector3.Angle() to calculate the angle between the two vectors. This makes it independent from the whole euler angles issue.


Note that when modifying the local euler angles in the inspector while in edit mode, the Unity editor actually stores the 3 euler angles internally which makes it easier to manipulate them through the handles in the scene view. You will notice that they can actually rotate beyond 360° which makes no sense under runtime conditions. Angles in general are a pain to work with since they wrap around either at 0° / 360° or at -180° / 180°


Quaternions on the other hand represent an orientation through a direction vector and the rotation around that vector. If you have never heard about quaternions before I always recommend this Numberphile video. Quaternions are quite tricky to understand since they represent a 4 dimensional number system. However they are just beautiful from a mathematical and practical point of view. If you want to know a little more about quaterions I can also recommend the 3B1B videos on quaterions

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 itisieric · Apr 11, 2020 at 09:01 PM

Thank you for getting back to me I'm having problems getting the angle to read the same as the inspector. See the two attached pictures. The 2 pictures should show the same angle because they are the same angle, but they show different numbers that don't mach up to what is in the inspector angle for X. thanks in advance for your help.

 public class HelpMe : MonoBehaviour

{ public float angle; public Transform getTransform;

 void Update()
 {
     angle = Vector3.Angle(getTransform.position, transform.position);

     Debug.Log(angle);
 }

}

[1]: /storage/temp/156424-2-pic.jpg


difrent-angles-but-it-should-be-the-same.jpg (289.1 kB)
2-pic.jpg (287.8 kB)
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

129 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

Related Questions

How is the rotation of a Transform converted into a Vector3 in the inspector ? 2 Answers

Rotation around z-axis always local space and not world? Vector-axis angle projection calcuations. 0 Answers

Whats the Difference Between Rotation EulerAngles and Quaternions? 2 Answers

How to get inspector rotation values ? 2 Answers

Commands affecting rotation not working 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