- Home /
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.
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.
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.
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.
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 :)
Sooo... Should I make every moon also orbit sun with same speed as the planet around which it is rotating?
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 :)
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]