butterfly_mc.onEnterFrame = function() {
butDistance = Math.sqrt(((this._x-_xmouse)(this._x-_xmouse))+((this._y-_ymouse)(this._y-_ymouse)));
if (butDistance<=250) {
this._x += (_xmouse-this._x)/10;
this._y += (_ymouse-this._y)/10;
}
};
I have this code which works awesomely for getting an mc to follow the mouse wile it is within a certain distance and it stops following it when it is out of the distance range. at the moment it comes to a dead stop but i was wondering what i would have to do to apply inertia to it so it comes to a gradual stop.
cheers.
butterfly_mc.x=0, butterfly_mc.y=0;
butterfly_mc.onEnterFrame = function() {
butDistance = Math.sqrt(((this._x-_xmouse)*(this._x-_xmouse))+((this._y-_ymouse)*(this._y-_ymouse)));
if (butDistance<=250) {
//THIS NOW ADDS TO THE SPEED, NOT TO THE POSITION
this.x += (_xmouse-this._x)/10;
this.y += (_ymouse-this._y)/10;
}
//HERE's A BIT OF FRICTION
this.x *= .92, this.y *= .92;
//AND HERE ITS ADDED TO THE POSITION
this._x += this.x, this._y += this.y;
};
i hope this helps :cowboy:
thanks very much, iv not tried implementing it yet but did look at your example. i’m not too keen on having it bouncing back and forth as i am applying it to a butterfly animation, is there a way to do it so it just gradually slows down?