So I'm working with a GUI script that needs to allow someone to drag the cursor by holding down the mouse button, but only to a certain distance away from where they started holding down that mouse button. After that point, the cursor should stay in the circle--but at an angle that's appropriate to where the cursor is outside of the circle. It's sort of the way that Angry Birds allows you to drag the bird a certain distance away from the slingshot, but then keeps the bird at the correct angle, even if you're dragging it farther than the slingshot will allow. So, I'm calculating the angle that the cursor is from the center of the circle correctly (i.e. 360 and 0 are when you're directly "above" it in the GUI, and 180 is below, and so on. However, when the cursor attempts to calculate its position, it's moving way too quickly around the circle. I think it has to do with these two lines of code. Do you guys know what I'm doing wrong, calculating the psoitions of the cursor? I realize this question is kind of vague, and perhaps hard to understand. But I've made a video of what's going on, so you can see what I mean...here's the code:
and here's the video:
asked Sep 28 '11 at 11:06 AM
Ok then. Assuming that you know the true position of the mouse, and the point at which you want the cursor to rotate, first you get the original offset:
Then you use this handy function called Atan2-
Then use that and your desired radius to reconstruct the correct location.
Then use the correctOffset to draw your cursor!
answered Sep 28 '11 at 12:19 PM