# Applying friction to a movieclip

**URL:** <https://forum.kirupa.com/t/applying-friction-to-a-movieclip/276601>\
**Category:** Uncategorized\
**Created:** [December 1, 2008, 2:48pm UTC](https://forum.kirupa.com/t/applying-friction-to-a-movieclip/276601 "2008-12-01T14:48:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![grebs](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@grebs](https://forum.kirupa.com/u/grebs)\
**Post date:** [December 1, 2008, 2:48pm UTC](https://forum.kirupa.com/t/applying-friction-to-a-movieclip/276601/1 "2008-12-01T14:48:35Z")

</div>

I have a movieclip that accelerates when the user presses the up key. I want this movieclip to slow down using friction when the user lets go of the up key. The code i have written is this -

var ground:MovieClip = new Ground;  
ground.x = 0;  
ground.y = 400;  
addChild(ground);

var xVel:Number = 0;  
const xAcc:Number = -0.25;  
const friction:Number = 0.9;

stage.addEventListener(KeyboardEvent.KEY\_DOWN, acceleration);  
function acceleration(evt:KeyboardEvent):void{  
if(evt.keyCode == Keyboard.UP){  
ground.x += xVel;  
xVel += xAcc;  
}  
else  
{  
xVel \* friction;  
}  
}

The accelerate part of the movieclip works fine but when i release the up button the movieclip just stops. Can anyone help?
