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

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

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

It’s worth looking.+

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


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.

oo Thanks suvenier :slight_smile:

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

Not a single flaw, i owe you one suvenier

[U][/U]