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 /
This question was closed Aug 17, 2014 at 10:25 PM by ikelaiah for the following reason:

Solved.

avatar image
0
Question by ikelaiah · Aug 14, 2014 at 11:53 PM · quaternionmathanglequaternions

Aligning child's axis to parent's axis - world space: Why does my Quaternion.Angle never return values close to zero when they visually are?

I am aligning an object's +z axes - which points downwards - to the parent's -y axis which points downwards. That is, I want the child object to face down all the time, in respect to parent's object down.

It works well by using the following code:

 // Obtain local forward vector relative to world
 Vector3 localForward = this.child.transform.forward;
 Debug.DrawRay(this.child.transform.position, localForward, Color.blue); // draw axes local space
 Debug.DrawRay(this.child.transform.position, -this.parent.transform.up, Color.green); // draw down axes parent space

 // Building the world (not-local) rotation from child's local z-axis to parent's y-axis
 Quaternion verticalDown = Quaternion.FromToRotation(localForward, -this.parent.transform.up) * this.child.transform.rotation;
 // apply it
 this.child.transform.rotation = Quaternion.Slerp(this.child.transform.rotation, vertical, Time.deltaTime * 1.0f);
    

It works well. However, in the default pose (child object's forward is down and parent's down is down) the following never equates to zero, but 89-91.

 Quaternion.Angle(this.child.transform.rotation, verticalDown);

Why is this so? I'd expect the value would be zero since both child's axes forward is facing down and parent's down is down in the beginning.

Comment
Add comment · Show 2
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 rutter · Aug 15, 2014 at 01:52 AM 1
Share

Look down.

Then, rotate 90 degrees to your right.

Your second rotation differs from your first by 90 degrees, but is still pointing in the same direction.

Any chance something like that is happening here?

avatar image ikelaiah · Aug 15, 2014 at 03:06 AM 0
Share

You nailed it! Case is now closed.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

22 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

Related Questions

quaternion - rotate camera based on original facing at scene start? 0 Answers

Rotating clockwise or counter clockwise using Quaternions and PID 0 Answers

Why is my Quaternion rotation going crazy? 1 Answer

Unity.Mathematics equivalent to Quaternion.FromToRotation? 3 Answers

How to Increase Height of Pendulum? 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