So I have a player character sprite, that rotates to follow the mouse cursor around, and a circle centered around the cursor:
I'm trying to calculate the coordinates of one of the points of the circle, that changes depending on the rotation of the player character, where the argument of the point will be equal to the rotation of the player character +90 degrees, so let's say I want to position a 10x10 blue rectangle shape at this point, it will looks like this:
If the player's rotation is equal to 180 => the point will have an argument of -90:
If the player's rotation is equal to 90 => the point will have an argument of 180:
If the player's rotation is equal to 135 => the point will have an argument of -135:
And, I'm half way there, here is my attempt at calculating the position of the rectangle (in the main loop), knowing that:
test is the blue square.
scope is the circle
25 is the radius if the circle (
scope)
scope's rotation is literally equal to that of the player character:
scope.setRotation(entity_sprite.getRotation());
So the player character's rotation and the circle's rotation are interchangeable.
test.setPosition(sf::Vector2f(player.scope.getPosition().x + cos(player.scope.getRotation() + 90) * 25, player.scope.getPosition().y + sin(player.scope.getRotation() + 90) * 25));
It...sort of works:
It doesn't appear in the gif because of low frame-rate, but the rectangle is spinning around the circle in the right directions, but it's doing it too quickly, I've had a similar problem when coding the character to follow the cursor, but I solved it by multiplying the angle outputted by the
atan2 function by by 180/3.14, it doesn't seem to be as straight forward here...
So, how do I calculate the coordinates of this point correctly?