Rotate according to mouse position?

Started by BloodShura, October 05, 2012, 22:02:50

Previous topic - Next topic

BloodShura

Hello guys.
First of all, sorry for my bad english, I'm brazilian ^^.

Well, I'm developing a 2D game, and I need to rotate my character (from 0 - 360), according to the mouse position - it is, where the character is looking.

I've tried so many things to do that, but none worked. Can someone help me, please?

Thanks ^^.

Daslee

Get rotation angle between two points. Here is method that i'm using:
public double getAngleBetween(double x1, double y1, double x2, double y2){
		return(Math.atan2(y1-y2, x1-x2));
	}


But this will not give you rotation angle in 0-360 this will give you in radians I think it's 0-7. Or you can't multiply those radians by 57.2957795 and then you'll get in degrees (0-360). So now to get rotation angle you must write: getAngleBetween(playerCenterX, playerCenterY, mouseX, mouseY);