I know, I know, on the internet there are a lot of tutorial on how to get the angle between the center of two objects.
Now I have this code:
// (180 / PI = 57.3065)float AngleBetweenVectors
(sf
::Vector2f, sf
::Vector2f);float AngleBetweenVectors
(sf
::Vector2f a
, sf
::Vector2f b
){ return 57.3065f * atan2(b.
y - a.
y, b.
x - a.
x);} that get the angle, and then this code that I use to calculate it:
float angle = AngleBetweenVectors(player_p, cursor.getPosition());
player.setRotation(angle);
where
player_p is the player center position (a 50x50 square sprite) and
cursor is the cursor sprite I use.
player is finally the player sprite.
But when I run it it gets this kind of problems (please watch the entire video):
http://www.youtube.com/watch?v=qaS151xUPeg&feature=youtu.beAs you can see on the border of the terrain it gets a little bit tricky. Why is that? I'm using two views like that:
window.clear(sf::Color(0, 0, 0, 255));
window.setView(camera); // camera view
// start drawing
terrain.draw(); // terrain blocks
window.draw(player); // player sprite
window.setView(cursor_camera); // cursor view
window.draw(cursor); // cursor sprite (the circular one)
// end drawing logic
window.display();
window.setMouseCursorVisible(false); // no mouse pointer please