Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Why child object not rotate with parent?

Discussion in 'Scripting' started by angelinais, Jul 22, 2017.

  1. angelinais

    angelinais

    Joined:
    Jun 17, 2017
    Posts:
    2
    Hey Guys,

    I'm not sure what's the problem but I'm trying to rotate gameobject and child when I click but it's strange because child is not rotate every time I clicked.

    Please watch my video clip.



    This is parent gameobject's code :

    Code (CSharp):
    1.  
    2. void OnMouseDown(){
    3.     transform.Rotate((0),(0),(90f));
    4. }
    and this is a child's code :

    Code (CSharp):
    1. void Update () {
    2.         transform.Rotate(0,5,0,Space.Self);
    3.     }
    Please let me know what I should do.

    Thanks
     
  2. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    this is only ran on mouse click

    this is ran all the time, and should always be rotating.

    this is why the child doesn't follow the parent

    is the child a subobject of the parent? that would be an easy way to rotate the child when the parent is clicked
     
  3. angelinais

    angelinais

    Joined:
    Jun 17, 2017
    Posts:
    2

    Yes, child is subobject of the parent. I still don't understand.

    This is in parent and it will rotate 90 degree when I click. Its work fine when I click.
    Code (CSharp):
    1. void OnMouseDown(){
    2.    transform.Rotate((0),(0),(90f));
    3. }


    This is in child and it is alway spin itself. Its work fine too.
    Code (CSharp):
    1. void Update () {
    2.    transform.Rotate(0,5,0,Space.Self);
    3. }
    But I don't understand. I'm not sure if I was wrong. Please give me a suggestion.
     
  4. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    this method works as expected for me on 2017.1.0f3.

    on click, parent and child rotate in increments on each click, child spins on it's local axis properly.

    do you have any other restraints or animations playing on the child?

    Made sure they aren't linked the wrong way in the hierarchy?
     
  5. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    it's possible that the Rotate in the update is overriding the parent.
    can you please remove that rotate in the Update and test it.
     
  6. simonlvschal

    simonlvschal

    Joined:
    Nov 17, 2015
    Posts:
    266
    did you set the child's rotation to follow parents rotation? so everytime u click the parent the child will follow.