Orbiting in AS2

http://www.actionscript.org/resources/articles/863/1/Orbiting-in-AS2/Page1.html

Andy Crockett

Loved writing code since I started a couple months ago, and I get pissed to see the lack of useful tutorials for widely used subjects on the web.

By Andy Crockett

Published on January 28, 2009

This is my first tut so here we go:

How to make an mc orbit another mc.

How to make an mc orbit another mc.

ActionScript

Go to File>New

Select ActionScript 2.0:

Create two MovieClips, Give the one which you wish to orbit around an instance name of "center" (no quotations)

the other you can name whatever you like. Lets say you named it bob.

Click on bob

open the actions panel (f9)

insert the following: (or type it out maually to help you remember)

onClipEvent(load){

angle=0//degrees

mainDistance=100//pixels

}

onClipEvent(enterFrame){

angle+=5

xDistance=Math.sin(angle * Math.PI/180)*mainDistance

yDistance=Math.cos(angle * Math.PI/180)*mainDistance

xDisCalculated=_root.center._x-xDistance

yDisCalculated=_root.center._y-yDistance

this._x=xDisCalculated

this._y=yDisCalculated

}

and if your looking for this in as3 its really not that hard to convert even if your a beginner,

but im too lazy to do it so sorry.

explained:

the onLoad is setting the variables "angle" and "mainDistance"

in the next block:

it adds 5 to the "angle" variable every frame

the "xDistance" is calculated using the sine of "angle" / radian( or Math.PI/180) times the "mainDistance" (how far away it is from the mc

the "yDistance" is calculated using the cosine of "angle" / radian( or Math.PI/180) times the "mainDistance" (how far away it is from the mc

then xDisCalculated is just the _x position of your object (in this case NAME) minus the xDistance

then yDisCalculated is just the _y position of your object (in this case NAME) minus the yDistance

next the object which your coding _x position is told to equal xDisCalculated

next the object which your coding _y position is told to equal yDisCalculated

Select ActionScript 2.0:

Create two MovieClips, Give the one which you wish to orbit around an instance name of "center" (no quotations)

the other you can name whatever you like. Lets say you named it bob.

Click on bob

open the actions panel (f9)

insert the following: (or type it out maually to help you remember)

onClipEvent(load){

angle=0//degrees

mainDistance=100//pixels

}

onClipEvent(enterFrame){

angle+=5

xDistance=Math.sin(angle * Math.PI/180)*mainDistance

yDistance=Math.cos(angle * Math.PI/180)*mainDistance

xDisCalculated=_root.center._x-xDistance

yDisCalculated=_root.center._y-yDistance

this._x=xDisCalculated

this._y=yDisCalculated

}

and if your looking for this in as3 its really not that hard to convert even if your a beginner,

but im too lazy to do it so sorry.

explained:

the onLoad is setting the variables "angle" and "mainDistance"

in the next block:

it adds 5 to the "angle" variable every frame

the "xDistance" is calculated using the sine of "angle" / radian( or Math.PI/180) times the "mainDistance" (how far away it is from the mc

the "yDistance" is calculated using the cosine of "angle" / radian( or Math.PI/180) times the "mainDistance" (how far away it is from the mc

then xDisCalculated is just the _x position of your object (in this case NAME) minus the xDistance

then yDisCalculated is just the _y position of your object (in this case NAME) minus the yDistance

next the object which your coding _x position is told to equal xDisCalculated

next the object which your coding _y position is told to equal yDisCalculated