Dear reader,
I am trying to let my sprite face the position of my mouse, it works almost, but it has some bugs.
It seems like the angle is not exactly right, and when I turn right, my sprite turns left, and vice versa.
Can someone tell me whats I did wrong? I think the problem is in my math calculations, since I have no
knowledge on math and stuff to be honest lol.
I checked on this forum, and found code which was almost like mine, and for them its working so no clue why it is not for me lol.
void character::lookAtMouse(sf::RenderWindow &win){
sf::Vector2f curPos = sprite.getPosition();
sf::Vector2i position = sf::Mouse::getPosition(win);
// now we have both the sprite position and the cursor
// position lets do the calculation so our sprite will
// face the position of the mouse
const float PI = 3.14159265;
float dx = curPos.x - position.x;
float dy = curPos.y - position.y;
float rotation = (atan2(dy, dx)) * 180 / PI;
sprite.setRotation(rotation);
}