SFML community forums

Help => General => Topic started by: paupav on November 23, 2015, 07:29:01 pm

Title: Rotating player depending on the mouse position
Post by: paupav on November 23, 2015, 07:29:01 pm
So basically I wanna make player1 rotate and always look at the cursor, but I'm stuck. For some reason code below doesn't work

 
click1Pos.x = (int)sf::Mouse::getPosition(cliff->window).x;
        click1Pos.y = (int)sf::Mouse::getPosition(cliff->window).y;
        moveToCursor = true;

        double one = playerYposition - mouseYposition;
        double two = playerX - mouseXposition;
        double tanges = (tan(one/two)* RAD);

        player1.setRotation(tanges);
Title: Re: Rotating player depending on the mouse position
Post by: BlueCobold on November 23, 2015, 07:46:47 pm
Shouldn't that be atan instead of tan? And are you sure you have to operate with angles in radians instead of degrees?
Title: Re: Rotating player depending on the mouse position
Post by: G. on November 23, 2015, 08:49:34 pm
It's atan2, and "sfml rotate mouse position" yields lots of results on google.
Title: Re: Rotating player depending on the mouse position
Post by: paupav on November 23, 2015, 09:42:10 pm
Shouldn't that be atan instead of tan? And are you sure you have to operate with angles in radians instead of degrees?

I'm not sure if there is any function that returns angle in degrees, but I0ve definded #define RAD 57.29 and at the end I simply multiply angle in radians with that constant.

It's atan2, and "sfml rotate mouse position" yields lots of results on google.

Idk why it worked, but it didn't work with atan.