# Circular Movement Towards Mouse At Set Speed

**URL:** <https://forum.kirupa.com/t/circular-movement-towards-mouse-at-set-speed/278946>\
**Category:** flash\
**Created:** [January 7, 2009, 10:19pm UTC](https://forum.kirupa.com/t/circular-movement-towards-mouse-at-set-speed/278946 "2009-01-07T22:19:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pi3rc3](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@pi3rc3](https://forum.kirupa.com/u/pi3rc3)\
**Post date:** [January 7, 2009, 10:19pm UTC](https://forum.kirupa.com/t/circular-movement-towards-mouse-at-set-speed/278946/1 "2009-01-07T22:19:24Z")

</div>

i have a MC that rotates around in a circle towards where the mouse is pointing but im trying to make it so it doesnt just go directly to point the mouse is pointing but instead moves at a certaint speed, heres my code:

```auto
var radius:Number = 50;
//The radius of the circle
var centerX:Number = 200;
//The center X position of the circle
var centerY:Number = 200;
//The center Y position of the circle
var toMouse:Boolean = false;
			
var ang:Number = Math.atan2(centerY-game.mouseY, centerX-game.mouseX);
//Rotate depending on mouse location
this.x = centerX+(Math.cos(ang)*radius)*(toMouse ? 1 : -1);
//Move along the X
this.y = centerY+(Math.sin(ang)*radius)*(toMouse ? 1 : -1);
//Move along the Y

```

any help is appreciated, thanks!
