0

i have this Problem now for over 2 days. Constantly tweaking. I just cant get it done.

I have a Player texture ( Player is facing the left on it ) which i want to rotate using the touchpad. So the player will be facing his running direction.

So far i have this :

double facerotation = Math.atan2(touchpad.getKnobPercentY(), touchpad.getKnobPercentX());

spriteBatch.draw(runningFrame, player.getPosition().x, player.getPosition().y, Player.getSize() / 2, Player.getSize() / 2, Player.getSize(), Player.getSize(), 1, 1, facerotation * 100, false);

But with "roation*100" he spins like 2 times around and without he barely rotates. I even tried switching the X and Y values for the atan2 function above. But i never got him rotate only in the direction i am Moving. I also tried the atan function, also with swapping the X and Y values.

Please help me. I tried thousands of ways, Different calculations and things i saw on google. Nothing brought me the desired effect.

MarvinJ
  • 3
  • 6

1 Answers1

1

Just use a Vector2. Use it to store your knob percent y and x. Then you can get the rotatation in degrees with vector2.angle().

Vector2 v = new Vector2(touchpad.getKnobPercentX(), touchpad.getKnobPercentY());
float angle = v.angle();
runningFrame.setRotation(angle);
Barodapride
  • 3,475
  • 4
  • 25
  • 36
  • 1
    Thank you so so so so much! Finally. Such a simple thing. ! – MarvinJ May 19 '16 at 21:14
  • Works great, except for in my case the sprite returns to its initial angle when the touchpad is released. Is there any way to keep its angle afterwards? – mikebrsv Jun 26 '16 at 17:59
  • Solved! Wrapped `runningFrame.setRotation(angle);` in the `if (touchpad.isTouched())` statement. – mikebrsv Jun 26 '16 at 18:06