Search Unity

Parenting a camera to an empty game object doesn't work?

Discussion in 'Getting Started' started by justkittycat2000, Apr 21, 2021.

  1. justkittycat2000

    justkittycat2000

    Joined:
    Apr 21, 2021
    Posts:
    3
    Hello everyone. I'm fairly new to Unity and these forms, so I apologize if I'm not doing this correctly. I'm trying to have a camera rotate around a small scene (a turn around basically) and I watched a tutorial that explains I can do this by creating an empty game object, resetting its transforms, and parenting the camera to the game object. I tried doing this, but even when I reset the transforms on the game object, the origin stays on the camera instead of the game object. If I unparent the camera, the origin of the game object goes back to the center again. I'm not really sure what I'm doing wrong? I hope I'm providing enough information to explain what I'm trying to do. If not, I'll try my best to explain further.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    What origin are you referring to? Could you take a screenshot of the problem for us?
     
  3. justkittycat2000

    justkittycat2000

    Joined:
    Apr 21, 2021
    Posts:
    3
    I'm sorry, I'm referring to the world origin. And yes.

    game object.png
    Here you can see the origin of the game object is in the center of the world.

    camera.png
    The origin of the camera is where the camera is located.

    camera in game object.png
    But when I parent the game object to the camera, the origin stays where the camera is, instead of moving to the origin of the game object, which is the world center.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    When you make an existing GameObject a child of another GameObject, it doesn't move the world space position of the new child object. It stays where it was. If you look at it's transform component, it shows you a new position relative to the parent though.

    What I think you're trying to do is make the Main Camera object a child of Camera Rotator. Once you do that, then set the position of the Camera object relative to that new parent, and make sure the Camera says it is not at 0,0,0. Then rotate Camera Rotator. I don't see any scripts attached to Camera Rotator, so I don't know if you are rotating the correct object.
     
    vendaar and justkittycat2000 like this.
  5. justkittycat2000

    justkittycat2000

    Joined:
    Apr 21, 2021
    Posts:
    3
    Aha! That was the problem. I had the tool handle position set to center, once I changed it to pivot, the origin changed to the game object and I was able to rotate the camera around it. I did have a script for it in my project with the same name of Camera Rotator, but I didn't attach it yet because it wouldn't have worked right until it was rotating around the correct position. Which it is now. Thank you very much for your help.
     
    RZ08 likes this.