FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
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

onClipEvent(load){
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 = 50;
//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);
}
angToRad = ang*Math.PI/180;
ob_mc._x = obPosX+radius*Math.cos(angToRad);
ob_mc._y = obPosY+radius*Math.sin(angToRad);
};


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

Adobe Flash Developer
Related topics
A ActionScript,showing a running date.
Syndicate Rich Media
Movement rotation action scrip
Flash 8 actionscript help - FIXED
Buying a logo for my site.
America is you, no matter who you are
Superstring Theory
The matrix online hints and tips
Actionscript 2.0... for and if together = buggy
ActionScript2.0 - importing an external movie clip
Need help with Actionscript 2.0
Actionscript 2.0 - add line break to string?
Looks crappy in Firefox
Flash ActionScript 2.0 Verical Animated Menu Problem
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.