Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Answered] Parent + Children not rotating correctly

Discussion in 'Scripting' started by kole9273, Oct 20, 2014.

  1. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13
    I'm currently using this function to try and rotate the parent:
    Code (CSharp):
    1. transform.Rotate(Vector3.forward, Time.deltaTime * 180, Space.World);
    but it's not rotating it like I want it to. It is rotating all the children in the parent the same exact way as parent.
    Here's a 15 second youtube video showing what I mean.



    How can I get the object to rotate like in the first part of the video?
     
    Last edited: Oct 20, 2014
  2. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13
    I've also tried transform.localEulerAngles = new Vector3(0,0,f);
    where f is incremented after every update, the results are the same.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Something mighty strange is going on there. You didn't specify which transform "transform" in your code is referring to, but I think this must be in a script you have running on all the children.

    If you actually rotated the parent, instead of each of the children, it would behave exactly like the first part of the video. I've done it many times; Unity would be seriously broken (and well near unusable) if it didn't work that way.

    So, please check where your script is, and make sure 'transform' refers to the parent, not the children.
     
  4. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13
    I'm running this script on the main camera. I attach the Circle gameobject (the parent object) to the script that is on the main camera, and only tell it to rotate.

    This is all the code:
    Code (CSharp):
    1.  
    2. public GameObject circle;
    3.  
    4. void Update(){
    5. circle.transform.Rotate(Vector3.forward, Time.deltaTime * 180, Space.World);
    6. }
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well I'm stumped. If you post your project somewhere, I'll download it and have a look. I'm sure with a bit of poking, the problem will reveal itself!
     
  6. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13

    Attached Files:

  7. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13
    Anybody?
     
  8. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Center the parent to the children:

    And remove the scripts from the child objects.
    You just want the part object to have the rotate script.
     
    kole9273 likes this.
  9. kole9273

    kole9273

    Joined:
    Oct 10, 2013
    Posts:
    13
    That works! Thanks!