• 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 AntLewis · Jul 12, 2017 at 07:40 PM · quaternionparent-child

Parent, Child and independent rotations

Hi there, I have an issue to do with a parent/child relationship and rotations. I need to be able to simultaneous lerp the parent objects rotation to a particular vector (currently I'm doing it with quaternion.lerp in a coroutine):

 transform.rotation = Quaternion.Lerp (startingRotation, targetRotation, timer * m_speedOfRotation);

...while at the same time, lerp the child objects rotation to a different vector. Obviously because of the parent/child relationship, the child is inheriting the rotation of the parent and screwing it all up. Is there a nice way that I can achieve this (I have to keep the parent/child relationship and I can't temporarily decouple them).

Thanks so much for any help!

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 Cornelis-de-Jager · Jul 12, 2017 at 09:46 PM

If I understand Quaternion's then this should be put in the child's rotation:

 void Rotate ( Quaternion target) {
      // Subtract the parents rotation from the current rotation
     Quaternion actual = target * Quaternion.Inverse (transform.parent.rotation);
      
    // Rotate to the actual target
    Quaternion.Lerp (transform.rotation, actual, timer * m_speedOfRotation);
 }


Logic behind

So when an object is parented with another object, his transform is based of the parents. Meaning both position and rotation at 0 will be equal to the parents rotation. So if you want it to be parented and have a direction according to world direction, you need to subtract the parents rotation first.

Comment
Add comment · Show 1 · 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 Bunny83 · Jul 12, 2017 at 10:03 PM 0
Share

That won't work. First of all you (mis-)use lerp as you use the current world rotation as start. This will result in a damped non-linear change. Since you use the current worldspace rotation you will still be affected by the parent rotation as the world space rotation is calculated based on the own local rotation and the parents rotation.

avatar image
0

Answer by Bunny83 · Jul 12, 2017 at 10:07 PM

If you don't want the child to inherit the parents position, rotation and scale, it should not be a child in the first place. If you just want to inherit the position that can be achieved by a script.

As alternative you can store the childs current worldspace rotation in a seperate variable. Do not read back the actual child rotation. Just lerp your own variable to your desired rotation and set the child's rotation each frame. Make sure you do this after the parent get rotated. As far as i know coroutines which yield null are run before Update. However if not you may want to use LateUpdate for the child adjustments.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

71 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

Related Questions

Rotation of child object is different in play mode 0 Answers

Different results with Matrix4x4.MultiplyPoint and Matrix4x4.rotation 0 Answers

How do I rotate a Rigidbody to a surface normal AND use camera rotation? 1 Answer

Quaternion and 360 degree rotations 1 Answer

Rotate GameObject on click 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