# Question: Drag Inertia

**URL:** <https://forum.kirupa.com/t/question-drag-inertia/23888>\
**Category:** flash\
**Created:** [June 23, 2003, 11:12pm UTC](https://forum.kirupa.com/t/question-drag-inertia/23888 "2003-06-23T23:12:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![slayerment](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@slayerment](https://forum.kirupa.com/u/slayerment)\
**Post date:** [June 23, 2003, 11:12pm UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/1 "2003-06-23T23:12:53Z")

</div>

Does anybody know how I could make a MC keep moving a certain amount when I let go after dragging it. I want the distance it goes to be based upon how quick I moved the mouse before I let it go. Thanks for any help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 23, 2003, 11:44pm UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/2 "2003-06-23T23:44:57Z")

</div>

This is concept code, meaning it may or may not work, but its purpose is to give you an idea of how to approach this situation:

```auto

if (dragging) {
ox = nx;
oy = ny;
nx = _root._xmouse;
ny = _root._ymouse;
} else {
_x += (nx-ox)/7;
_y += (ny-oy)/7;
ox = nx;
oy = ny;
nx = _x;
ny = _y;
}

```

alright, this basic code keeps track of the previous location of the ball or whatever you’re working with and based on the distance between the points, it determines its velocity when you release it. when you do, it still records the points and eventually slows down (because of the divide by 7, this eases the object, or slows it down).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 12:14am UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/3 "2003-06-24T00:14:16Z")

</div>

thoriphes already gave you the answer, but i figured i’d post it anyway… 😛

```auto
MovieClip.prototype.inertialDrag = function(ratio, decel) {
	var x, y, xspeed, yspeed, drag;
	this.onEnterFrame = function() {
		if (!drag) {
			this._x += xspeed *= decel;
			this._y += yspeed *= decel;
		} else {
			x = this._x;
			y = this._y;
			this._x = this._parent._xmouse;
			this._y = this._parent._ymouse;
		}
	};
	this.onPress = function() {
		drag = true;
	};
	this.onRelease = this.onReleaseOutside=function () {
		drag = false;
		xspeed = (this._x-x)*ratio;
		yspeed = (this._y-y)*ratio;
	};
};
// usage
myMovieClip.inertialDrag(.1, .95);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 12:23am UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/4 "2003-06-24T00:23:35Z")

</div>

Thanks guys, this works great! Perfect 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 12:24am UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/5 "2003-06-24T00:24:14Z")

</div>

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 2:40am UTC](https://forum.kirupa.com/t/question-drag-inertia/23888/6 "2003-06-24T02:40:17Z")

</div>

excellent!
