# Can someone help me on how to make a movieclip rotate to the position of your mouse?

**URL:** <https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873>\
**Category:** Uncategorized\
**Created:** [May 20, 2008, 4:58pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873 "2008-05-20T16:58:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpgfanatic](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rpgfanatic](https://forum.kirupa.com/u/rpgfanatic)\
**Post date:** [May 20, 2008, 4:58pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/1 "2008-05-20T16:58:07Z")

</div>

It’ll probably seem simple to guru’s but it’s like looking at a blank wall for me :S,  
could you help me with finding the formula to determine the rotation for the movieclip ?  
(a gun in this case, along with the arm), since the rotation will determine the path of the bullet it fired.

My guess it has something to do with radials, but that’s just a guess

Thank you a lot in advance

---

<div class="post-metadata">

**Author:** ![bpalermo](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bpalermo](https://forum.kirupa.com/u/bpalermo)\
**Post date:** [May 20, 2008, 5:24pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/2 "2008-05-20T17:24:15Z")

</div>

Here in Kirupa, at the 3D Flash tutorials they have a short page on the basic trigonometry knowledge you’ll need for this and many other features:

[http://www.kirupa.com/developer/actionscript/trigonometry.htm](http://www.kirupa.com/developer/actionscript/trigonometry.htm)

It’s worth looking.+

---

<div class="post-metadata">

**Author:** ![rpgfanatic](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rpgfanatic](https://forum.kirupa.com/u/rpgfanatic)\
**Post date:** [May 20, 2008, 7:34pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/3 "2008-05-20T19:34:07Z")

</div>

Thanks for the url :), it has really helped me a lot

So i can be pretty ■■■■ sure the code has to go something along these lines

The one thing that bugged me the most was how to find out the radius after reading what you sent me, but i found out that to determine the actual radius of the arm mount point compared to the mouse position, that it had to be something like this

radius = [SIZE=2][FONT=Courier New, Courier, mono][SIZE=2][COLOR=#000080]Math[/COLOR].[COLOR=#000080]sqrt[/COLOR][/SIZE][/FONT][/SIZE]((\_xmouse - arm.\_x)_(\_xmouse - arm.\_x) +(\_ymouse-arm.\_y)_(\_ymouse-arm.\_y))

And building on that this formula i could derive=\>

arm.\_rotation = Math.PI([SIZE=2][FONT=Courier New, Courier, mono][SIZE=2]Math.[/SIZE][/FONT][/SIZE][SIZE=2][FONT=Courier New, Courier, mono][SIZE=2]atan2[/SIZE][/FONT][/SIZE]((\_ymouse-arm.\_y)[SIZE=2][FONT=Courier New, Courier, mono][SIZE=2], [/SIZE][/FONT][/SIZE](\_xmouse - arm.\_x)))\*2

I’ll try it out now

---

<div class="post-metadata">

**Author:** ![suvenier](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@suvenier](https://forum.kirupa.com/u/suvenier)\
**Post date:** [May 20, 2008, 7:34pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/4 "2008-05-20T19:34:09Z")

</div>

```auto

function focus(obj,xm,ym)
{
 obj.rot = -Math.atan2((obj._y - ym ),(xm - obj._x ))*180/Math.PI;
 obj._rotation = obj.rot;
}

```

xm, my PLACE where u want obj to rotate to.

---

<div class="post-metadata">

**Author:** ![rpgfanatic](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rpgfanatic](https://forum.kirupa.com/u/rpgfanatic)\
**Post date:** [May 20, 2008, 7:41pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/5 "2008-05-20T19:41:27Z")

</div>

oo Thanks suvenier 🙂

(i made a mistake on my own, and posted this before reading the post of ye, hence the edit)

---

<div class="post-metadata">

**Author:** ![rpgfanatic](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@rpgfanatic](https://forum.kirupa.com/u/rpgfanatic)\
**Post date:** [May 20, 2008, 7:50pm UTC](https://forum.kirupa.com/t/can-someone-help-me-on-how-to-make-a-movieclip-rotate-to-the-position-of-your-mouse/260873/6 "2008-05-20T19:50:28Z")

</div>

Not a single flaw, i owe you one suvenier

[U][/U]
