Draw an imaginary triangle using three points. The origin (center of
your movie), the mouse, and the third point is where the perpendicular from your
mouse intersects the x axis. Now, what we are trying to find is the angle theta,
the only way we can find it is using a bit of trigonometry.
Tan (theta) = Opposite side / Adjacent side
theta (angle we are trying to find) = tan -1 (opposite side/adjacent side)
now, we need to find out opposite side and adjacent side, which is easy
adjside = _root._xmouse-_root.origin._x;
oppside = -1*(_root._ymouse-_root.origin._y);
we have multiplied oppside with -1 as flash cartesian system is flipped along
x axis (which means y axis is upside down). In normal scenarios, descending
down the y axis from top to bottom shows a decrease in y, in flash it increases.
now, we have to find the tan -1, flash has a function Math.atan2() for that
angle = Math.atan2(oppside, adjside);
this function returns the values in radians, we still need to convert it in
degrees
angle = Math.round(angle/Math.PI*180);
Finally, just make a movie clip and put the above code in onClipEvent (mouseMove)
so flash will calculate the mouse angle for you whenever it changes.
0-360 ? again posted by: Gary on:Sep 22, 08 5:54 pm
Adding 180 to my textbox created innapropriate angles, so:
I had an idea to make it be 360.
I added 360 to my entire angle, then I tried to an add if statement that would make any angle < 360 to stay the same, but and angle > 360 to be itself - 360 (so -70 = 290, -25 = 335, 14 still = 14)
But it disreguardes my if statement completely:
if (angle > 360) {
angle = angle-360;
} else {
angle = angle;
}
is there a problem with my if or is it just being mean :'(
What would we have to do to get this to display 0-360, instead of negative values?
The reason I ask is because I'd like assign a 'go to' value to the result so that I could successful revolve around an object, that I've animated, and assigned to a 360 frame movie clip???