Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Xentarok · Jul 06, 2013 at 01:10 PM · prefabspacemoon

Moon rotation problem.

Hello. So I have this problem with my moons rotation. This is the script (It's attached to the planets):

 float Distance = transform.localScale.x + Random.Range(10,20);
         
 Instantiate(Moon,new Vector3(transform.position.x + Distance,0,transform.position.z), Quaternion.Euler(0,0,0));
 
 (in Update)
 
 Moon.transform.RotateAround(transform.position, Vector3.up, 0.7f * Time.deltaTime);


The problem is, that moons get placed but they don't rotate around planets. alt text

I was thinking about attaching the rotation code to the Moon prefab, but I'm not sure how would this work.

-Xentarok

P.S - Forgive me any language mistakes.

moons.jpg (80.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Em3rgency · Jul 06, 2013 at 01:44 PM

You want to rotate the thing you instantiated, not the general prefab you have declared.

 float Distance = transform.localScale.x + Random.Range(10,20);
 GameObject myMoon;
  
 myMoon = (GameObject) Instantiate(Moon,new Vector3(transform.position.x + Distance,0,transform.position.z), Quaternion.Euler(0,0,0));
  
 (in Update)
  
 myMoon.transform.RotateAround(transform.position, Vector3.up, 0.7f * Time.deltaTime);

Turn myMoon into an array or list, and properly fill it up with instantiated moons, and you can make a cycle that rotates all of them, so you would have more than 1 moon per planet.

Comment
Add comment · Show 5 · 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 Xentarok · Jul 06, 2013 at 02:07 PM 0
Share

Thanks, It's working, except for one small detail, it seems that if $$anonymous$$oons aren't fast enough they can't keep up with the planets, thus the distance between the moon and the planet is increasing. It starts doing tht when your angle per second (in this code 0.7) is smaller than about 40.

avatar image Em3rgency · Jul 06, 2013 at 02:16 PM 0
Share

Well, yes, if you made the planet move too, your moons should also be taken into account.

So from the suns perspective, when you move a planet around it, you should act as if its moons are the same object, as part of that planet, and also make them move around it the same way. Only then you make the moon also orbit the planet.

This is a rather complex problem all in all :)

avatar image Xentarok · Jul 06, 2013 at 02:23 PM 0
Share

Sooo... Should I make every moon also orbit sun with same speed as the planet around which it is rotating?

avatar image Em3rgency · Jul 06, 2013 at 02:26 PM 0
Share

Of course! Everything in a solar system orbits the sun. But some things, like moons ALSO orbit their plants. And in fact, as the sun orbits the galaxy center, so do its planets, and their moons. So moons actually orbit 3 things at once :)

avatar image Xentarok · Jul 06, 2013 at 02:30 PM 0
Share

Yeah, it's a complicated world :D Thanks anyway :)

avatar image
0

Answer by sdsada · May 27, 2014 at 08:37 AM

[url=http://www.youtube.com/watch?v=1OwLUrgMTVU] French Open Live Stream[/url]

[url=http://www.youtube.com/watch?v=jwQfRVb1lhY] French Open 2014 Live Stream[/url]

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Filling a scene with prefabs programmatically 2 Answers

Two exact objects behaving differently... *scratches head* 0 Answers

Storing a part of a complex asset in an asset bundle 1 Answer

Switch the prefab of a game object from a script 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