Forums

ForumsProgramming Forum

Solar system know-how.

Posted Nov 23, '11 at 3:01pm

torgal

torgal

7 posts

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?

 

Posted Nov 23, '11 at 3:09pm

PixelSmash

PixelSmash

579 posts

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

 

Posted Nov 23, '11 at 4:46pm

torgal

torgal

7 posts

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

 

Posted Nov 23, '11 at 8:31pm

master565

master565

4,288 posts

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

 

Posted Nov 23, '11 at 10:48pm

Carlytoon

Carlytoon

329 posts

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 :D

 

Posted Nov 24, '11 at 3:56am

torgal

torgal

7 posts

@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?

 

Posted Nov 24, '11 at 10:19am

master565

master565

4,288 posts

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.
 

Posted Nov 24, '11 at 5:20pm

PixelSmash

PixelSmash

579 posts

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 ;)

 

Posted Nov 25, '11 at 8:49am

torgal

torgal

7 posts

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.

 

Posted Nov 29, '11 at 3:04am

torgal

torgal

7 posts

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.

 
Reply to Solar system know-how.

You must be logged in to post a reply!