# Friction help

**URL:** <https://forum.kirupa.com/t/friction-help/211594>\
**Category:** flash\
**Created:** [January 3, 2007, 1:32pm UTC](https://forum.kirupa.com/t/friction-help/211594 "2007-01-03T13:32:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daidai](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/daidai/32/3087_2.png) [@daidai](https://forum.kirupa.com/u/daidai)\
**Post date:** [January 3, 2007, 1:32pm UTC](https://forum.kirupa.com/t/friction-help/211594/1 "2007-01-03T13:32:55Z")

</div>

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

```auto

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;
}

```
