4 Replies Latest reply on Jul 7, 2007 7:49 AM by Rothrock

# Clip drifting away

How can I avoid that the movie clip is drifting away with the following script below?
Whit this script, the clip is turning in circles, but step by step driften away from the original position

var i=0
MyMovie_mc.onEnterFrame=function(){
this._x+=5*Math.cos(i)
this._y+=5*Math.sin(i)
i+=0.1
}

Thanks,
Johnny
• ###### 1. Re: Clip drifting away
I can't explain the reason although I found a way to visualise it and a way to avoid it.
kglad usually makes an appearance soon and he's the resident math expert. Perhaps he'll be able to shed light on it.

Check out the 2 options below.

• ###### 2. Re: Clip drifting away
I was working in the same direction. As my object is not following the full path of a circle (just an arc section of a circle and then coming back - as a pendulum), I created two reference points (orig_x1 and orig_x2) at both ends of its path. This keeps the object on its place but on each path end you can percieve a small hesitation (that's when the correction happens).
So I think I am gonna use tweening with motion guides to get my object moving.
But for a correct motion I need two motion guides for one single object?
Just imagine: my object in a line, and both ends are following the path of a arc. But the arcs do not have the same circle diameter. Suggestion?
Anyway, I like to thank you for your reaction on the drifting subject.
Johnny
• ###### 3. Re: Clip drifting away
your code is defines a path along a spiral.

if you don't want your movieclip to move along a spiral don't increment the _x, _y properties, just assign them like in gwd's alternative approach.

for a pendulum motion using actionscript, you''ll need 4 tweens. two start the motion and two to execute onMotionFinished.

in your onMotionFinished define a toggle to alternate the start and end points of your tween.

if you're tweening in the authoring environment, you should be able to create motion from left to right (or right to left) along your arc and then copy and paste those reversed frames to complete the motion.
• ###### 4. Re: Clip drifting away
My guess would be twips. Yup, twips!

That is twentieth of a pixel and also the "resolution" that flash uses for moving things on stage. So anything finner that .05 will be dropped from the _x and _y you are setting. And with sin and cos that is a lot!

So instead of directly setting your positions with the calculations assign them to a currentX/currentY (or whatever) do the calculations there and then assign them to the _x and _y.

Also GWD post is a great solution with regard to controlling it. You can even rename orig_x to centerX and then manipulate that over time to cause drift that you DO want.

Finally if you are doing pendulum motion, I would suggest looking at rotation instead of circular motion. Here is a page:

http://www.myphysicslab.com/pendulum1.html

Near the bottom there is this equation: