Rotating a movie clip with mouse

Hello everyone!

Hope life is good

What I am trying to do is get an arrow to spin and always point at the curser.

What I have done is created to movie clips, one that is empty but has this code (this clip has the instance name of clip)


x = (_root._xmouse - _root.comp._x);
y = (_root._ymouse - _root.comp._y);
hyp = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
cos = x / hyp;
rad = Math.acos(cos);
deg = Math.floor(180/(Math.PI / rad));

if(y <0){
    deg = -deg;
}else if((Math.floor(y) == 0) && (x <0)){
    deg = 180;


trace("x = " + x);
trace("y = " + y);
trace("hyp = " + hyp);
trace("cos = " + cos);
trace("rad = " + rad);
trace("deg = " + deg);

On the second movie clip I have an arrow and the following code (this clip has an instance name of comp)

this._rotation = _root.clip.deg;

I can only get it to follow the cursor for 90 degs not the full 360.

Any help would be well helpful


Hmm… mine rotates all the way.

It does go all the way around.

the only thing that was weird …In your code for the comp object, the code starts with clip.deg.

either something was left out, or that came over by mistake.

Well I don’t know what I did wrong then but it does not work for me. I found a new way of doing it that was less code and easier to understand (for me that is).

I made controller clip named “clip” and added this code…

onClipEvent (enterFrame) {
// arrow rotation
a = arrow._y-_ymouse;
b = arrow._x-_xmouse;
angleA = Math.atan2(a, b);
degrees = angleA/(Math.pi/180);

made an arrow MC and named it “arrow” with this code
this._rotation = _root.clip.degrees;

This formula made more sense, for me that is.

Thanks for the input. Maybe I should try the first code again, and maybe I shouldn’t!

Thanks again for your time Iammontoya