Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rotation

Status
Not open for further replies.

esromneb

Programmer
Mar 30, 2002
76
US
Hi, I'm trying to make an object spin accorting to the location of the mouse. For instance, I have a horizontal line as a movie clip, we will call this rotator, it's in a movie clip called holder. This is what my code looks like and it's almost right.

holder.rotator._rotation = Math.atan((holder._ymouse)/(holder._xmouse))*60;

(the code is a loop)

The line sorta follows the mouse but not really. It also reverses rotation when you move it above and left of the center of rotation. Please help.
-ben
 
The code you want to perform the maths is:

_rotation = Math.atan2(_root._ymouse-_y, _root._xmouse-_x)/Math.PI*180;

...so I'm guessing (can't be sure of your paths etc) what you want is:

holder.rotator._rotation = Math.atan2(_root._ymouse-holder.rotator.__y, _root._xmouse-holder.rotator.__x)/Math.PI*180; Slainte

 
It gets a bit confused whe hovering directly above the center point...


Regards,
new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top