 Home
 Tutorials
 Flash
 Intermediate
 Orbiting in AS2
Orbiting in AS2
ActionScript
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.
View all articles by Andy CrockettSelect 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._xxDistance
yDisCalculated=_root.center._yyDistance
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
Spread The Word
Attachments
9 Responses to "Orbiting in AS2"
said this on 12 Feb 2009 1:22:03 PM CDT
Really cool science here.
http://ho 
said this on 17 Feb 2009 12:55:37 PM CDT
Nice explanation of the m
it would be easie onClipEvent(load){ } onClipEvent(enterFr angle+=5; yDistance=Math. xDisCa yDisCalcu this._x=xDis this._y= } 
said this on 02 Mar 2009 4:10:55 AM CDT
hi, first off, very good
I made something simil But now I want Can my email is grtz 
said this on 23 Mar 2009 7:35:02 PM CDT
Pieter, all you would nee
yPo xPos=this._x_root.cen angle2=Math.atan this._rotation=angle if bob isn't facing That shoul 
said this on 12 Jun 2009 8:51:11 AM CDT
I tried this, first typin

said this on 12 Jun 2009 8:57:13 AM CDT
Cancel that last comment.

said this on 15 Jul 2009 8:16:29 AM CDT
now nest this 5 levels de

said this on 08 Sep 2009 11:48:05 PM CDT
This is great!
And I als But I require to dra An As far as I knew,I d Please Thanks a lot.. 
said this on 10 May 2011 7:18:43 AM CDT
Can you show me how to ma
