# AS2 / Math problem: Make one MovieClip orbit another MovieClip

**URL:** https://forum.kirupa.com/t/as2-math-problem-make-one-movieclip-orbit-another-movieclip/331127
**Category:** flash
**Created:** [May 22, 2013, 3:10pm UTC](https://forum.kirupa.com/t/as2-math-problem-make-one-movieclip-orbit-another-movieclip/331127 "2013-05-22T15:10:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Naxirus](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@Naxirus](https://forum.kirupa.com/u/Naxirus)
#### Post date: [May 22, 2013, 3:10pm UTC](https://forum.kirupa.com/t/as2-math-problem-make-one-movieclip-orbit-another-movieclip/331127/1 "2013-05-22T15:10:45Z")

</div>

I’m using the code below to make a MovieClip rotate and move towards another MovieClip. I’d like to figure out how to instead have the first MovieClip rotate towards the second MovieClip and move sideways, effectively orbiting around the second MovieClip. I’m assuming the math for such a thing is terribly difficult. If someone could help me out with this I’d be quite grateful.

```auto
this.rotDir = Math.round(180 - ((Math.atan2(this.focus._x - this._x, this.focus._y - this._y)) * 180 / Math.PI));
this._rotation = this.rotDir; this.speed = 2;
this.velocityX = Math.sin(this._rotation * Math.PI / 180) * this.speed;
this.velocityY = Math.cos(this._rotation * Math.PI / 180) * -this.speed;
this._x += this.velocityX; this._y += this.velocityY;

```
