# Mouse follow with easing tutorial

**URL:** https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487
**Category:** Uncategorized
**Created:** [April 28, 2003, 6:13pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487 "2003-04-28T18:13:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)
#### Post date: [April 28, 2003, 6:13pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/1 "2003-04-28T18:13:12Z")

</div>

here’s my adapted code from lostinbeta’s tutorial for easing on mouse click

put this code on the first frame

```php

speed = 1;
onMouseDown = function () {
	endX = _root._xmouse;
	endY = _root._ymouse;
};
onEnterFrame = function () {
	dot._x += (endX-dot._x)/speed;
	dot._y += (endY-dot._y)/speed;
};

```

make a symbol called ‘dot’ and put it on the \_root stage

if you change speed to 5 the script works just fine … moving the ball to the point with easing. but i want it without easing … just a steady movement.

i made this script

```php

xspeed = (dot._x - endX)/10;
yspeed = (dot._y - endY)/10;
onMouseDown = function () {
	endX = _root._xmouse;
	endY = _root._ymouse;
};
onEnterFrame = function () {
	if (dot._x>=endX) {
		dot._x -= xspeed;
	}
	if (dot._x<endX) {
		dot._x += xspeed;
	}
	if (dot._y>=endY) {
		dot._y -= yspeed;
	}
	if (dot._y<endY) {
		dot._y += yspeed;
	}
};

```

but when i put that on there the \_x and \_y don’t get done at the same time. so it doesn’t go in a straight line to the new point … it turns a corner when the \_x or \_y is complete. depending on which one gets done first

---

<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: [April 28, 2003, 6:37pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/2 "2003-04-28T18:37:04Z")

</div>

Well what are you trying to do? If you want it to ease to the point at the same time, why don’t you just use the first code? It does exactly what you said you want it to.

---

<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: [April 28, 2003, 6:38pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/3 "2003-04-28T18:38:26Z")

</div>

i don’t want it to ease … i don’t want it to jump. i just want it to move at a constant rate.

like:  
if (\_x\<300){  
\_x += 10;  
}

does that make sense?

---

<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: [April 28, 2003, 6:41pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/4 "2003-04-28T18:41:38Z")

</div>

no… i don’t think it does. Do you mean like an elastic effect? If so, there is a tutorial for that on this site.

---

<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: [April 28, 2003, 6:47pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/5 "2003-04-28T18:47:27Z")

</div>

no  
no elasticity no easing nothing special. just move to wherever the mouse has clicked

if the mouse is clicked at 300x300 then i want the dot to move to 300x300. but not jump, so setting the \_x and \_y to the \_xmouse and \_ymouse onMouseDown would not work. I want it to move there. no easing … just move at a steady rate

---

<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: [April 28, 2003, 6:56pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/6 "2003-04-28T18:56:25Z")

</div>

i’m a bit busy right now but i’ll give a hint… 🙂  
check the random movement tutorial. 😉

---

<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: [April 28, 2003, 6:58pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/7 "2003-04-28T18:58:20Z")

</div>

> \*Originally posted by kax \*  
> \*\*i’m a bit busy right now but i’ll give a hint… 🙂  
> check the random movement tutorial. 😉 \*\*

Precisely 🙂

In order to do what you want to do you will have to use trig to get the distancex and distancey and find the hypotenuse to travel along. I actually have to go now too, but hopefully that helps.

---

<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: [April 28, 2003, 7:02pm UTC](https://forum.kirupa.com/t/mouse-follow-with-easing-tutorial/19487/8 "2003-04-28T19:02:12Z")

</div>

yup. 😛 =)
