# Convert MathAtan2 angle to degrees

I use an angle to set the velocity (or direction if you prefer) of my sprite, however, I want the sprite to be heading in the same angle as I'm moving, rotating according to that angle.

How I set angle and velocity:

angle = (float)Math.atan2(0 - pos.y, 220 - pos.x); //using bottom mid of screen as destination for testing

//in update
pos.x += 200 * Math.cos(angle) * delta;
pos.y += 200 * Math.sin(angle) * delta;
sprite.setPosition(pos.x, pos.y);

//in render
sprite.draw(batch);


is there any way to use this value in LibGdx's "sprite.rotate()" function? I can't do "sprite.rotate(angle)". Can I do this some other way? Can I convert my angle-value somehow to degrees? I'm stuck.

I tried

sprite.rotate((float)Math.toDegrees(angle));


but that gave rly weird results, the following image is moving down and to the right

• "rly wierd results" how? That says nothing about the result you got. – ratchet freak Oct 10 '15 at 0:41
• Hmm, hard to explain, Ill post an image – Green_qaue Oct 10 '15 at 0:41
• Is it the same as in stackoverflow.com/q/27345132/731620 ? – ratchet freak Oct 10 '15 at 0:45
• I tried using sprite.setRotation((MathUtils.radiansToDegrees * angle)); but getting wrong result still. I dont actually rotate it in update, since it never changes direction I set the angle in the constructor, after the position has been set. – Green_qaue Oct 10 '15 at 0:51
• @ratchetfreak added an image – Green_qaue Oct 10 '15 at 0:53

rotate takes I believe a relative rotation while angle is an absolute rotation. In other words take the difference between the current angle and the wanted angle and pass that to rotate.
Or pass just the angle into setRotation.