# Applying inertia

**URL:** <https://forum.kirupa.com/t/applying-inertia/186568>\
**Category:** Uncategorized\
**Created:** [April 22, 2006, 1:16pm UTC](https://forum.kirupa.com/t/applying-inertia/186568 "2006-04-22T13:16:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 22, 2006, 1:16pm UTC](https://forum.kirupa.com/t/applying-inertia/186568/1 "2006-04-22T13:16:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NinoScript](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ninoscript/32/1484_2.png) [@NinoScript](https://forum.kirupa.com/u/NinoScript)\
**Post date:** [April 22, 2006, 2:15pm UTC](https://forum.kirupa.com/t/applying-inertia/186568/2 "2006-04-22T14:15:08Z")

</div>

```auto
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:

---

<div class="post-metadata">

**Author:** ![willgoldstone7](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/willgoldstone7/32/2251_2.png) [@willgoldstone7](https://forum.kirupa.com/u/willgoldstone7)\
**Post date:** [April 22, 2006, 6:00pm UTC](https://forum.kirupa.com/t/applying-inertia/186568/3 "2006-04-22T18:00:26Z")

</div>

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?
