# Arrow Rotation which follows Mouse?

• 02-22-2005, 12:50 AM
pechos
Arrow Rotation which follows Mouse?
Hello,

I am trying to achieve an effect that I believe is probably fairly easy for the right person. Picture a flash movie with a crosshair pattern on it. In the middle of the cross hair I have a simple arrow which I simply want to rotate (staying centered), to point and follow the movement of the mouse on the screen. So basically all is said and done the arrow would be capble of rotating anywhere inbetween 360 degrees, depending on where the mouse is.

Any help or direction would be most appreciated.
If need be I can point you to a preview of the page I am trying to do this with.

Thanks!

:mrpimp:
• 02-22-2005, 01:23 AM
jbum
Does the arrow point *at* the mouse? Or does its position indicate the direction of mouse movement (e.g. if mouse moves up, arrow points up)?
• 02-22-2005, 01:26 AM
pechos
The arrow would need to Point AT the mouse. So the tip of the arrow would always be pointing directly at the mouse.
• 02-22-2005, 01:27 AM
jbum
Does the crosshair movie move, or is it stationary? If it moves, what causes it to move?
• 02-22-2005, 01:30 AM
jbum
Attached is a movie which does what you describe.

The code, attached to the crosshair movie, reads as follows:

code:
```

onClipEvent(enterFrame)
{
var dy = _root._ymouse - this._y;
var dx = _root._xmouse - this._x;
this.arrow._rotation = Math.atan2(dy,dx)*180/Math.PI;
}
```

• 02-22-2005, 01:35 AM
pechos
I took a peek at the clip you sent. Looks exaclty like what I need.
Awesome, Thanks.
• 02-22-2005, 02:04 AM
jbum
Cool - remember that your arrow must point to the RIGHT when it is at zero rotation, in order for that code to work.
• 02-22-2005, 02:12 AM
pechos
any way to get it so it can start off from 90 degrees, straight up?
• 02-22-2005, 02:25 AM
jbum
Yeah, change this line as follows:

this.arrow._rotation = Math.atan2(dy,dx)*180/Math.PI + 90;
• 02-22-2005, 03:00 AM
pechos
sweet.
:doughnut: