Planet Rotation and Cameras

Been playing about with rotation and cameras
please take a look at the web html
http://jameslamonte.com/planet_rotation.html
The planet IS orbiting the sun object its just very slow,but look at the moon,its going upwards.
The code i am using is from the unity manual
this bit for the Earth,the moon is a child with no
code attached atm.

function Update() {
// Slowly rotate the object arond its X axis at 1 degree/second.
transform.Rotate(Vector3.right * Time.deltaTime);
}

This bit is the code for the earth to orbit the sun

function Update() {
// spin the object around the world origin at 20 degrees/second.
transform.RotateAround (Vector3.zero, Vector3.right, 0.0001 * Time.deltaTime);
}

The few questions I got is,
How do I change the vector to have the moon orbit the earth along the correct axis while the earth orbits the sun,and how would I implement a “spaceship” type camera so I can visit the planets?
thanks in advance for any help,this is all new to me.

The simple case is:
(a) A gameObject (call it EarthContainer) orbits the Sun at 1AU.
(b) Inside EarthContainer is Earth (at local 0,0,0) – tilted at 22 degrees or so and rotating on its axis – and a MoonContainer, orbiting local 0,0,0, with a Moon inside it, etc. etc.

In general, when you run into this kind of problem, sticking your object inside a gameObject (essentially an empty coordinate system you can hang objects and behavior off) is the solution.

Similarly, you might have a ShipContainer that holds a ship model and a camera. This would let you do things like move the camera without moving the ship, and move the ship without changing your view (unless you wanted to) or the ship’s direction of travel (e.g. you might want to “roll” a ship as it turns, but just as a cosmetic effect).

ok got the Earth upright and rotating correctly,of course its speeded up,but i got some nice atmospheric effects going now with multiple cloud layers.
http://jameslamonte.com/planet_rotation2.html

the moon is child of earth and doesnt rotate so thats sorted,just gotta fix up a camera,or do like you said podperson,and grab a spaceship :slight_smile:

Well the moon does rotate – it just happens to rotate at the same speed it orbits :wink: