# How to move towards the mouse with a fixed speed?

**URL:** <https://forum.kirupa.com/t/how-to-move-towards-the-mouse-with-a-fixed-speed/251015>\
**Category:** programming\
**Created:** [February 4, 2008, 4:35pm UTC](https://forum.kirupa.com/t/how-to-move-towards-the-mouse-with-a-fixed-speed/251015 "2008-02-04T16:35:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluemagica](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bluemagica](https://forum.kirupa.com/u/bluemagica)\
**Post date:** [February 4, 2008, 4:35pm UTC](https://forum.kirupa.com/t/how-to-move-towards-the-mouse-with-a-fixed-speed/251015/1 "2008-02-04T16:35:54Z")

</div>

Ok how do i make an object move towards the mouse(prefferably on a key press) but with a fixed speed. currently i am using:  
if(Key.isDown(Key.UP))  
{  
\_x+=Math.round((\_root.\_xmouse-\_x)/20);  
\_y+=Math.round((\_root.\_ymouse-\_y)/20);  
}

as you can see the speed depends on distance to mouse and hence is not constant…so what do i do?

PS: i am using flash 8 pro
