Rotate player around different axis by mouse?

hi there,
i figured out a way how to rotate an actor by mouse around a point other than his center. or better to put the actor in a certain distance to the center of rotation.
it looks like this:
http://imageshack.us/photo/my-images/200/screenshot20110909at124.png/
the problem is, this only works as long as the mouse is outside of the circle of rotation - when inside it jumps at highspeed between two locations on the rotation.
any idea how to fix this?
i figured out a way how to rotate an actor by mouse around a point other than his center. or better to put the actor in a certain distance to the center of rotation.
it looks like this:
http://imageshack.us/photo/my-images/200/screenshot20110909at124.png/
the problem is, this only works as long as the mouse is outside of the circle of rotation - when inside it jumps at highspeed between two locations on the rotation.
any idea how to fix this?
Comments
Here is a fun one -- invert the vector to angle equation to make your game have a super strong mouse avoidance engine. Like this:
vectorToAngle( self.Position.X - game.Mouse.Position.X , self.Position.Y - game.Mouse.Position.Y )
Anyway, the actor flipping is because that is what the equations are telling it to do. Its a logic error. Its like saying: If the mouse is on the left then, go to the left of the mouse AND If the mouse is on the right, then go to the right of the mouse. It will start going back and forth in and endless attempt to satisfy both constraints. (Only your game does it in 360 degrees.) It is the vectorToAngle part that is the culprit.
Hope that helps
RThurman
You have probably already figured it out by now but someone else might be interested in how to solve this.
As hinted above, the vectorToAngle formula is the culprit. It is calculating the angle to a moving target. (And the target is moving in such a way that the next angle calculation is telling it to move back to its original spot.) That is why the actor is flipping back and forth.
Its a wicked little math problem.
The solution is to give it a fixed target. Instead of using the actor's x and y position, use the center of where you want the actor to 'patrol' around. In your specific case you are using the x,y coordinates of 500,300. So... you need to change your constrain behavior to read:
Constrain Attribute: self.offaxis To: vectorToAngle( game.Mouse.Position.X -500, game.Mouse.Position.Y -300)
Hope this helps!
RThurman