You are invited to Log in or Register a free Frihost Account!

# Actionscript 2.0 - How do I make a clip move in a circle?

Ragerin
As the title says; how do I make a movieclip move in a circle, only using actionscript and a premade movieclip?

Since I'm not THAT old, I haven't learned about Sin and Cos, yet - I know I have to use both, though, to get it working.

I've thought about making two functions.

 Code: B A     C           D

One function, that makes the movieclip move in a half circle ( A -> B -> C)
And another function, that makes it move from C -> D -> A.

So basically;

MC x & y == A

function1:
if MC position == A:
Move MC constant y & increase x

function2:
if MC position == C:
Move MC constant -y & increase -x

I hope I was understandable.

Any hints / help is highly appreciated.

-Ragerin
phyconinja
untested

xspeed=5;
yspeed=5;
xpos=this._x;
ypos=this._y;
this._x+=49;
this._y+=49;
}
onClipEvent(enterFrame){
this._x-=xspeed;
this._y+=yspeed;
if(this._x<xpos-70 || this._x>xpos+70){
xspeed*=-1;
}
if(this._y<ypos-70 || this._y>ypos+70){
yspeed*=-1;
}
}

let me know if it works.
hiquality
Hello Ragerin,
The following example is Tested and working
Use this code with a movieclip with the registration point in the middle and with the instance name of "ob_mc"

ang = 0;
//Don't change this
obPosX = 100;
//X position of the center for the circle describing the circular path
obPosY = 100;
//Y position of the center for the circle describing the circular path
//radius of the circle describing the circualr path
speed = 7;
// set the Speed
dir = 1;
// direction, use 1 for Clock Wise and -1 for Counter Clock Wise
this.onEnterFrame = function() {
ang += dir*speed;
if ((ang>360) || (ang<-360)) {
ang = dir*Math.abs(ang%360);
}
};

If you have any questions don't hesitate to ask
If you want me to send you the fla file just give me your e-mail address

Regards,
Oliver