Posts | ||
---|---|---|
Character Rotation Based On Mouse | Locked | |
Thread Options | ||
Jan 26 2013 Anchor | ||
How would I rotate an image in Slick2D to point to the mouse at all times? |
||
Jan 26 2013 Anchor | ||
get the direction vector pointing from the character to the mouse via vector subtraction then convert it to an angle via atan2 |
||
Jan 26 2013 Anchor | ||
Still doesn't work. Here's the source code:
|
||
Jan 26 2013 Anchor | ||
oh I forgot to mention you also need to normalize the vector before you atan2 it. If it still doesnt work one common issue is to make sure tha the rotation angle format and your input format match. AKA Radians vs Degrees. Here's an example function I did for getting the direction vector:
This tutorial might also be of help to you : |
||
Jan 26 2013 Anchor | ||
Can you repost that in java form? |
||
Jan 27 2013 Anchor | ||
It would be exactly the same except for the function declaration. public static function GetNormalizedDirectionVector(vec1X:Number, vec1Y:Number, vec2X:Number, vec2Y:Number):DoVector2f would become something like public Vector2 GetNormalizedDirectionVector(float vec1X, float vec1Y,float vec2X,float vec2Y) |
Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.