Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DaiMangouDev · Aug 17, 2016 at 11:25 PM · c#rotationquaternioneuler

How make child object rotate inverse to its parents rotation ?

Hi guys , I thought that this would be easier done then said but I was wrong.

I have an object in my scene named ParentObject and it has a child object named Pivot

Pivot has a line render on it(just to help us visualize the rotation)

Picture:

we see that the parent and child rotation values are all 0, which is good. if we rotate our parent object, the child object will follow the parents rotation as expected but we do not want this. alt text

Because the child rotation should always be inversely proportional to the parent rotation it will appear to be at a 0,0,0 rotation , which i what we want. So common sense would tell us that all we need to do is add or add or subtrack some rotational value from the child rotation to bring it back to what APPEARS to be a 0,0,0 rotation. but that does not work

Look at the now rotation values and the direction in which the Y axis is now in.

if we change the y value of the child object to compensate for the Y rotation of the parent , then line will tilt and everything goes wrong.

alt text

eg1.png (133.1 kB)
eg2.png (126.9 kB)
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
1

Answer by gangafinti · Aug 17, 2016 at 11:43 PM

This works fine for me:

 using UnityEngine;
 using System.Collections;
 
 public class RotationTest : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
         transform.Rotate (0.0f, 1.0f, 0.0f);
         transform.GetChild (0).Rotate (0.0f, -1.0f, 0.0f);
     }
 }

Comment
Add comment · Show 6 · 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 gangafinti · Aug 17, 2016 at 11:45 PM 0
Share

Try not to set euler angles manualy, always use Quaternion.Euler but in this case you can use the Rotation method that avoids the whole euler angles/Quaternion mess.

avatar image DaiMangouDev gangafinti · Aug 18, 2016 at 12:22 AM 0
Share

Yeah I was using Quaternion and Euler ... most confusing things ever.

But the Rotate Function is creating a constant rotation which is not good

avatar image DaiMangouDev · Aug 18, 2016 at 12:20 AM 0
Share

sorry, that just gives a continuous rotation . i'm lost now

avatar image gangafinti · Aug 18, 2016 at 12:28 AM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class RotationTest : $$anonymous$$onoBehaviour {

     float angleToAdd = 45;

     void Start () {
         transform.rotation = Quaternion.Euler (transform.eulerAngles.x, transform.eulerAngles.y + angleToAdd , transform.eulerAngles.z);
         transform.GetChild (0).rotation = Quaternion.Euler (transform.eulerAngles.x, transform.eulerAngles.y - angleToAdd , transform.eulerAngles.z);
     }
 }

This should do what you want.

avatar image DaiMangouDev gangafinti · Aug 18, 2016 at 12:41 PM 0
Share

Are you testing with a line render attached to your child object like in the example ?

avatar image gangafinti DaiMangouDev · Aug 18, 2016 at 08:45 PM 0
Share

I tested it with 2 cubes aka gameobjects and it worked. A line renderer should make no difference, because its the transform you are turning. The line will always face the camera maybe thats what you mean, becuase as far as I know you can't turn that.

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

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

Quaternion to Euler conversion singularities 0 Answers

Limiting the camera's rotation using quaternions, camera sticking to top/bottom limit angles 0 Answers

Flip over an object (smooth transition) 3 Answers

Particle System Instantiate's With Original Rotation - C# 1 Answer

Rotation with a slider 2 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