PDA

View Full Version : Smooth movement


kayleigh
05-19-2004, 10:30 AM
Hi guys,
I'm a beginner to actionscript, I need something I think should be simple, but I can't get it. I have a circle on stage (a movieclip) and I want it to move very smoothly, like floating, in the bounds of a certain area. Could someone help me out on this?
Thanks :-)

avatar
05-19-2004, 10:38 AM
I use this script a lot:

coef = 0.4;
_global.Fmove = function(targ, xpos, ypos) {
targ.createEmptyMovieClip("mc_move", depth++);
targ.mc_move.onEnterFrame = function() {
dx = xpos-targ._x;
dy = ypos-targ._y;
targ._x += (dx*coef);
targ._y += (dy*coef);
if ((Math.round(dx+targ._x) == Math.round(xpos)) && (Math.round(dy+targ._y) == Math.round(ypos))) {
targ._x = xpos;
targ._y = ypos;
targ.mc_move.onEnterFrame = undefined;
removeMovieClip(targ.mc_move);
}
};
};

Usage: Fmove(_root.myMC, 100, 200);
Change x(100) and y(200) coordinates as you like. Speed is changed by coef... Just play with it...

kayleigh
05-19-2004, 11:02 AM
Thanks, Avatar, for the quick answer. I played a bit with the script and, although useful, it's not what I was looking for. The script produces a smooth movement from point to point, I'd need my movieclip to move in a square area, a random floating-like movement.

I tried some scripts I did, but the result is not what I need, it doesn't look like the circle is floating at all.
Any clues?

Cheers,
Kayleigh