# Easing out & in object that follows mouse curser

**URL:** <https://forum.kirupa.com/t/easing-out-in-object-that-follows-mouse-curser/265179>\
**Category:** Uncategorized\
**Created:** [July 5, 2008, 11:31am UTC](https://forum.kirupa.com/t/easing-out-in-object-that-follows-mouse-curser/265179 "2008-07-05T11:31:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![limeman](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@limeman](https://forum.kirupa.com/u/limeman)\
**Post date:** [July 5, 2008, 11:31am UTC](https://forum.kirupa.com/t/easing-out-in-object-that-follows-mouse-curser/265179/1 "2008-07-05T11:31:37Z")

</div>

Hi,

I’m having difficulties trying to ease in & out an object which follows the mouse curser.

Basically i’m looking for a delayed (ease out) reaction for when I move the mouse, so when the object finally catches up with the curser it eases in.

Here’s a link to the FLA

[http://www.abreaks.co.uk/foecentre/Example\_5-5a%20rotating%20arrow.fla](http://www.abreaks.co.uk/foecentre/Example_5-5a%20rotating%20arrow.fla)

Here’s the code as well:

stage.addEventListener (Event.ENTER\_FRAME, rotate);  
var xvelocity:Number = 2;  
var yvelocity:Number = 2;  
var vx:Number = 0;  
var vy:Number = 0;  
var thrust:Number = 0.2;  
var myarrow:Arrow = new Arrow();  
myarrow.x = stage.stageWidth/2;  
myarrow.y = stage.stageHeight/2;  
var vr:Number = 5;  
addChild (myarrow);  
myarrow.gotoAndStop (1);

function rotate (evt:Event):void  
{  
var dx:Number = stage.mouseX-myarrow.x;  
var dy:Number = stage.mouseY-myarrow.y;  
var angle:Number = Math.atan2(dy,dx);  
myarrow.rotation = angle\*180/Math.PI;

}

If anyone could help that would be great!

Kind regards,

LM

---

<div class="post-metadata">

**Author:** ![Sage\_of\_Fire](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Sage\_of\_Fire](https://forum.kirupa.com/u/Sage_of_Fire)\
**Post date:** [July 5, 2008, 12:44pm UTC](https://forum.kirupa.com/t/easing-out-in-object-that-follows-mouse-curser/265179/2 "2008-07-05T12:44:10Z")

</div>

Well, I don’t have something that does rotation and easing, but I do have something for just easing. I’m sure you can get the gist of it and add it to your script. Here’s the code (credit to _Learning ActionScript 3_):

```auto

var ball:MovieClip = new Ball();
ball.x = ball.y = 100;
addChild(ball);

addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
function onLoop(evt:Event):void { 
	ball.x += velFriction(ball.x, mouseX, 8);
	ball.y += velFriction(ball.y, mouseY, 8);
}

function velFriction(orig:Number, dest:Number, coeff:Number):Number {
	return (dest-orig)/coeff;
}

```

---

<div class="post-metadata">

**Author:** ![limeman](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@limeman](https://forum.kirupa.com/u/limeman)\
**Post date:** [July 5, 2008, 1:01pm UTC](https://forum.kirupa.com/t/easing-out-in-object-that-follows-mouse-curser/265179/3 "2008-07-05T13:01:56Z")

</div>

cheers sage I will give it a go!!!

Thanks for your help,

LM
