I have a movieclip called Dent_D, which moves around the screen depending on where the mouse cursor is. It works fine, but I would like to have it so that it looks like it is affected by friction, i.e. slows down towards the end of its movement, but I cant work out how to do so - does anyone know how to help?
many thanks
dai
init();
function init():Void
{
centerX = Stage.width / 4;
centerY = Stage.height / 4;
txt_D_RangeX = (Dent_D._width - Stage.width + 500) / 2;
txt_D_RangeY = (Dent_D._height - Stage.height) / 3;
Dent_DcenterX = Stage.width / 4;
Dent_DcenterY = Stage.height / 4;
Dent_D._x = Dent_DcenterX;
Dent_D._y = Dent_DcenterY;
}
function onEnterFrame():Void
{
this.a +=1;
this._y = 100+Math.abs(10*Math.sin(this.a*.3));
this._rotation += Math.cos(this.a*.3);
this._x +=Math.cos(this.a*.3);
var dx:Number = _xmouse - centerX;
var dy:Number = _ymouse - centerY;
var angle:Number = Math.atan2(-dy, -dx);
var txt_D_Speed:Number = ((Math.sqrt(dx*dx + dy*dy))* .3);
var Dent_Dvx:Number = Math.cos(angle) * txt_D_Speed;
var Dent_Dvy:Number = Math.sin(angle) * txt_D_Speed;
if(Dent_D._x >= (centerX + txt_D_RangeX)){
Dent_D._x = centerX + txt_D_RangeX;
}
if(Dent_D._x <= (centerX - txt_D_RangeX)){
Dent_D._x = centerX - txt_D_RangeX;
}
if(Dent_D._y >= (centerY + txt_D_RangeY)){
Dent_D._y = centerY + txt_D_RangeY;
}
if(Dent_D._y <= (centerY - txt_D_RangeY)){
Dent_D._y = centerY - txt_D_RangeY;
}
Dent_D._x += Dent_Dvx;
Dent_D._y += Dent_Dvy;
}