ForumsProgramming ForumSolar system know-how.

13 5965
torgal
offline
torgal
7 posts
Nomad

I cant figure how to create an earth revolution around the sun and in the same moment moon orbiting earth.
I can only create simple earth revolution around the sun (without moon in motion).
Could anyone help me?

  • 13 Replies
PixelSmash
offline
PixelSmash
566 posts
Nomad

Could you give a little more information? At the moment, we don't even know what program you're using

torgal
offline
torgal
7 posts
Nomad

Of course, it might help Adobe Flash CS5
http://i43.tinypic.com/29nfec0.jpg

master565
offline
master565
4,104 posts
Nomad

Do you actually need it to rotate with programming? Or can you just animate the rotation of the third planet.

Carlytoon
offline
Carlytoon
324 posts
Nomad

well in programming you can do this:

//Declaring moon and earth angle, this will cause rotation;
var earthAngle:Number=0;
var moonAngle:Number=0;

//Distance of earth from the sun;
const earthDistance:int=96;

//Distance from moon from the earth;
const moonDistance:int=24;


addEventListener(Event.ENTER_FRAME,updateMovie);

//Updating the movie;
function updateMovie(e:Event):void
{
//Adding a little amount of rotation for orbit;
earthAngle+=.02;
moonAngle+=.08;

//This will make the earth and moon orbits properly.
earth.x=sun.x+(Math.cos(earthAngle)*earthDistance);
earth.y=sun.y+(Math.sin(earthAngle)*earthDistance);

moon.x=earth.x+(Math.cos(moonAngle)*moonDistance);
moon.y=earth.y+(Math.sin(moonAngle)*moonDistance);
}

The code is in AS3 and is just a sample, anyway if you have any problem with it just ask to me and I will explain to you every detail of the script

torgal
offline
torgal
7 posts
Nomad

@Carlytoon:
thank you so much for your help! Now please give me some time to figure it out (I'm a beginner in AS and flash at all).

@master565:
I do and I don't, it's hard to explain actually...
Would you show me how to create such system without AS?

master565
offline
master565
4,104 posts
Nomad

Would you show me how to create such system without AS?


I'm not really the best at animation, but you could try to animate the planet going in a circle using motion guides. The only problem with this is that the moon and earth will be treated as on object, and the hit boxes will be screwed up if you don't preform pixel perfect hit tests.
PixelSmash
offline
PixelSmash
566 posts
Nomad

I think Carlytoon posted an excellent piece of code, but if you want to stay away from code, you could use timeline tweens, or as master565 suggested motion guides (which is essentially an elaborate timeline tween). Since it's my suggestion, I'll try and explain the tweening approach.

Basically, you'll want a nested structure, meaning you have movieclips inside movieclips. Add the sun movieclip, and inside it place the earth movieclip. The pivot point of the earth movieclip should be centered on the sun, but the actual movieclip itself should be at the right orbit, ofcourse.
This way, you can rotate it around the sun. So, make a new keyframe at -say- frame 30, and rotate the earth 360 degrees. Next you right-click the frames in between the keyframes, and add a classic tween. If you scroll back and forth, you should see the earth rotating around the sun!

(By the way, if you want to avoid having a duplicate frame, which makes it seem like the animation pauses for a little while, right-click on the frame before the second keyframe, and add a keyframe there. Then remove the last keyframe, so that when the animation is at it's end and goes back to the beginning it doesn't show two frames with the earth at the same rotation)

Doing the moon is essentially the same, only inside the earth movieclip. Just add it, move the pivot point to the center of the earth, rotate, add keyframes and a tween.

Note that this does not include any realistic rotations of earth or the moon, if you want it very realistic I'd really recommend using code since it gives you a lot more control

torgal
offline
torgal
7 posts
Nomad

You guys are very helpful. Now I will take some time and will back to You soon. Hopefully, with the work done.
Thank You once again.

torgal
offline
torgal
7 posts
Nomad

I FAILED.
I add movie clip (planet), then motion path. Afterwards I click this symbol and draw new symbol (moon) inside and new motion path. I tried about 30 times in different ways, no result..
Fun is over it is just depressing now.

Carlytoon
offline
Carlytoon
324 posts
Nomad

Keep trying, superation needs effort and constancy, I hope you can do it

Darkroot
offline
Darkroot
2,763 posts
Peasant

Fun is over it is just depressing now.


Welcome to beginner programming and normal programming to a degree.

Keep trying, superation needs effort and constancy, I hope you can do it


Yep I agree. The code is pretty simple except for that math but if you just take it for what it is then even that isn't hard. It's not like you're doing derivatives.
torgal
offline
torgal
7 posts
Nomad

Oh, I forgot to write that I finally did it!
You can download the file here.
Sun earth moon revolution
PS
I hope I am not breaking any rules of the nforum.

Smokeshow
offline
Smokeshow
69 posts
Peasant

NIce! You made it !

Showing 1-13 of 13