Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 domsson · Feb 09, 2016 at 02:21 PM · quaternioneulerrotationslocaleulerangles

Setting a local rotation via script results in a 180 degree difference in actual rotation

I have a character and I'm trying to set some of it's joint's local rotations to certain values (clamping them, to be precise). The results were different from what I've been expecting, so I checked the results during run-time in the inspector. It turns out that whatever value I set programatically, in the end, the joint's rotation will be different by exactly 180 degree (plus or minus), as can be seen from the editor or checked via code. In a related questions, it was recommended to use go.localEulerAngles, but this results in the same problem. Can you tell me why this is happening?

Current code:

 Vector3 jointRot = joint.localEulerAngles; // Getting the current rot
 Debug.Log (joint.name +" before: "+jointRot);
 jointRot.x = Mathf.Clamp (jointRot.x, jointMin.x, jointMax.x);
 jointRot.y = Mathf.Clamp (jointRot.y, jointMin.y, jointMax.y);
 jointRot.z = Mathf.Clamp (jointRot.z, jointMin.z, jointMax.z);
 Debug.Log (joint.name + " fixing: " + jointRot);
 joint.localEulerAngles = jointRot; // Setting it to the clamped version
 Debug.Log (joint.name +" after: "+joint.localEulerAngles);

Previously, I was using this line to set the altered rotation, but it gives the exact same results:

 joint.localRotation = Quaternion.Euler (jointRot);

The output (elbow as example) on the console reads as follows:

 lowerarm_r before: (322.5, 140.2, 14.2)
 lowerarm_r fixing: (160.0, 140.2, 0.0)
 lowerarm_r after: (20.0, 320.2, 180.0)

So although I'm setting localEulerAngles to (160, 140, 0), it will now hold the value (20, 320, 180), which is different by 180 degree each. The documentation on localEulerAngles reads:

Unity automatically converts the angles to and from the rotation stored in Transform.localRotation

I assume this is what is causing the issue, but I don't understand why. I would assume all this does is convert the euler angels to a Quaternion.

To add to the confusion, sometimes it seems to work just as expected:

 lowerarm_r before: (7.2, 347.8, 1.7)
 lowerarm_r fixing: (10.0, 347.8, 0.0)
 lowerarm_r after: (10.0, 347.8, 0.0)

I'm grateful for any insight.

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Fixing the rotation around a particular axis using Quaternions? 2 Answers

am I using degrees, radians, rotation or quaternion ? 2 Answers

Inverse Quaternion data from Kinect 1 Answer

Quaternion.LookRotation with an offset. 1 Answer

Quaternion.Euler rotations don't add up 0 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