• 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
1
Question by PegLegJoe · May 19, 2011 at 10:05 AM · rotating

Rotating a child around its parent

I've got a small sphere that's parented to a larger sphere and I just need it to rotate around the larger sphere's z-axis, kind of like how the moon rotates around the earth. I can get it to rotate around its own axis, but I'm not sure how to rotate around the parent's.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by synapsemassage · May 19, 2011 at 11:21 AM

make a empty gameobject, place it at the parent's position. make the empty gameobject a child of the parent object. make the moon a child of the empty gameobject. rotate the empty gameobject around z. the child (moon) will follow.

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 cjmarsh · May 19, 2011 at 11:45 AM 0
Share

This method is much faster than trying to derive the rotation of the moon on it's own. The extra game object is essentially adding an extra 4 dimensions to make the rotation operation much simpler.

avatar image
4

Answer by Mnescat · May 19, 2011 at 11:37 AM

rotations that require a movement component have a center point (in more complicated movements there can be multiple groups you can rotate around at the same time but let's skip that for now)

If you do now know how to create a circular motion around a single point in space you can find the "how to" here: http://unity3d.com/support/documentation/ScriptReference/Transform.RotateAround.html

A sample is given there that uses some basic value which describe your object's orbitpoint

Comment
Add comment · Show 3 · 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 VioKyma · Sep 03, 2013 at 12:05 AM 1
Share

This is the more "correct" way of doing this. It's also the most tidy. +1

For the sake of people co$$anonymous$$g here later, I will expand on this answer:

 public void Update()
 {
     transform.RotateAround(transform.parent.position, new Vector3(0, 1, 0), rotateSpeed * Time.deltaTime);
 }

And to deter$$anonymous$$e the distance from the parent object, simply set the transform position relative to the parent

 Vector3 childPos = transform.parent.position;
 childPos.x -= 0.5f
 transform.position = childPos;


You can do this as soon as you have a parent object assigned for the child.

avatar image j2l2 VioKyma · May 26, 2016 at 03:28 PM 0
Share

Thanks! I was stuck with rotate and finally found this 3y old reply. Need far more examples in Unity docs.

avatar image DotusX · Dec 15, 2014 at 03:24 AM 0
Share

this helped me, thanks. Not a high enough rating to up-vote yet.

avatar image
0

Answer by MAD_dev · May 19, 2011 at 11:01 AM

Since you're comparing to the moon. We only see just a bigger half of the moon while it is rotating. If you want something similar, it's quite easy, although transform.LookAt might not what you need:

 void Start(){
     GameObject go = GameObject.FindGameObjectWithTag("Earth");
     Transform target = go.transform;
 }

 void Update(){
     transform.LookAt(target);
 }
 


Instead you can use if you only want to rotate the z axis (note what's inside the Quaternion.LookRotation function).

 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(new Vector3(target.position.x , target.position.y , transform.position.z))), 5 * Time.deltaTime);

Something like that.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotating a linear number - How? 0 Answers

How can i follow an object by 1-axis-rotation? 0 Answers

character rotates when using third person controller! 0 Answers

Preventing the first person controller from rotating 1 Answer

How can I get my 2D enemy to rotate to look at my player? 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