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
0
Question by Faradday · Mar 18, 2014 at 10:26 PM · transformquaternionbonelookrotationgimbal-lock

Quaternion rotation issue

After importing a model from Blender I found out it had bones totally messed up, they're all pointing to weird directions, and therefore having wrong forwards. So what I'm trying to do, since I need to rotate them from script, is to apply some kind of rotation offset before the rotation itself. What I have so far is this:

         transform.rotation = Quaternion.AngleAxis(y, Vector3.up) *
                              Quaternion.AngleAxis(z, Vector3.forward) *
                              Quaternion.AngleAxis(x, Vector3.right) *
                              Quaternion.LookRotation(target - transform.position);

Where x, y and z are offset degrees on 3 axes, and target is the point I'm trying to make my bone point at. After finding the right offset rotation it does indeed work, but the further away I move the object that has the bone attached, the more those offsets mess up, to the point they're not even close to poiting at the target.

I've tried using the transform right, up and forward instead of world axes, but this causes Gimbal Locks and crazy jittering at certain angles. I'm pretty sure I'm missing something on Quaternion rotations, but really I couldn't find anything for this problem.

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
Best Answer

Answer by Faradday · Mar 19, 2014 at 03:56 PM

I've managed to do it! In fact all I was trying to do was to rotate my bone towards a specific point, but instead of pointing its forward against it, i needed to have an arbitrary local direction vector pointing at it (its right, in fact). This is what I did, in case anyone needs it:

 public static void RotateForwardToDirection(Transform transform, Vector3 forward, Vector3 direction)
     {
         Quaternion baseLook = Quaternion.LookRotation(direction.normalized, Vector3.up);
         transform.rotation = baseLook;
         Quaternion newLook = Quaternion.LookRotation(transform.TransformDirection(forward), transform.up);
         transform.rotation = newLook;
     }

Where forward is the arbitrary forward (passing Vector3.right will make the right component of the transform to point at the desired direction and so on).

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

20 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

Related Questions

Simple Transform question, using Quaternion.LookRotation 0 Answers

Rotate object without storing facing 1 Answer

Unity animator with blender bones causes gimbal lock. 1 Answer

Gimbal Lock with Quaternions 0 Answers

Unity Rotate Raycast on Quaternion 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