Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 SaltedPepper12 · Mar 16, 2021 at 06:55 PM · transformquaternionworldspaceinverse kinematiclocalrotation

How do you set a local rotation for 1 axis but keep the other axis world space untouched?,How do you set the local rotation of 1 axis without effecting the world rotation of others?

I have an inverse kinematics rig with the animation rigging package and I need the forearm to rotate on the y axis (along the arm) locally. However, Unity doesn't seem to have any functions for only setting the local axis. They have Transform.Rotate which is close, that rotates around the local axis according to a CHANGE but I need to SET it.

Another similar function I saw was Quaternion.AngleAxis but that doesn't seem to work either since it wants to completely reset my rotation and my arm points straight up, removing the work of the inverse kinematics.

Perhaps it's my lack of knowledge in Quaternions, if anyone has an answer that would be great!

Thank you,I have an inverse kinematics setup for my VR rig and I need to keep the rotations for my forearm all the same besides the local Y axis (down the arm) to make it rotate depending on how your hand is facing.

There's not very many functions available for Quaternions that I could see for this and I can't use something like Transform.Rotate since this would result in it being a change in value compared to setting the value.

Really lost on what to do now so if anyone could help me with the math that would be great. Maybe I'm just not understanding Quaternions since they are rather complicated.

Comment
Add comment · Show 5
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 unity_ek98vnTRplGj8Q · Mar 16, 2021 at 08:30 PM 1
Share

Have you tried just a simple

 transform.localRotation = Quaternion.Euler(0,  yAngle, 0);
avatar image SaltedPepper12 · Mar 16, 2021 at 08:44 PM 0
Share

@unity_ek98vnTRplGj8Q wouldn't that just zero out my X and Z values though?

avatar image unity_ek98vnTRplGj8Q SaltedPepper12 · Mar 16, 2021 at 09:22 PM 0
Share

Yes you're right, my bad, but you can use Quaternion.Euler to apply an additive rotation to your default rotation every frame.


What I would do is set up your arm to its default rotation and capture that rotation on start up. Then you can use a Quaternion.Eulers to create an additional rotation about the arm's local y axis, and then apply that on top of the default rotation every frame.


 Quaternion defaultLocalRotation;
 
 void Start(){
     defaultLocalRotation = transform.localRotation;
 }
 
 void Update(){
     Quaternion yRotation = Quaternion.Euler(0, yRotationAngle, 0);
     localRotation = defaultLocalRotation * yRotation;
 }


avatar image SaltedPepper12 · Mar 17, 2021 at 12:33 AM 0
Share

@unity_ek98vnTRplGj8Q Thanks this worked! However, I still am having some troubles with my inverse kinematics because of the constraints it has. Looking like I'm gonna have to write it all myself manually (rotations). Having a hard time wrapping my head around quaternions especially converting between eulers, degrees, and some other things like localrotation vs rotation (not just saying it's local vs world). Do you know of any tutorials or articles I can look into?

Thanks!

avatar image unity_ek98vnTRplGj8Q SaltedPepper12 · Mar 17, 2021 at 03:43 PM 1
Share

Unfortunately I don't have any tutorials off the top of my head, but there are tons of questions on this forum that have pretty good explanations of quaternions and rotations

1 Reply

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

Answer by logicandchaos · Mar 17, 2021 at 12:58 PM

You simply plug the original rotational values back into it like this:

transform.localRotation = Quaternion.Euler(transform.localRotation.x, yAngle, transform.localRotation.z);

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

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

transform.localRotation resets after rotation 1 Answer

How can I get an OverlapBox with the exact same size and position as a BoxCollider? 1 Answer

Write a C# script to record GameObject rotation? 4 Answers

NullReferenceException by localRotation And Quaternion.Euler!?? 1 Answer

What is the rotation equivalent of InverseTransformPoint? 3 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