SFML trying to get a sprite to track mouse

If was writing your code, I did it like this:

float dX = mousePosition.x - sprite.x;//vector, collinear straight line whicn crosses sprite an cursor on X axis;
float dY = mousePosition.y - sprite.y;//same, but to Y axis;

float angle = (atan2(dY, dX)*180)/3.14159;//CALCULATING ANGLE
sprite.setRotation(angle + 90);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top