Hello SFML-Communiy,
I have a problem which makes me go crazy.
I try to move and turn a sprite in the direction of the cursor.
But it isn´t working very well.
The turning is almost working. But when i start moving the sprite the turning fails. (I think the center is moving or something like that
)
The code for turning looks like the following:
float dx = App->GetInput().GetMouseX() - (playerPos.x - player.GetCenter().x);
float dy = App->GetInput().GetMouseY() - (playerPos.y - player.GetCenter().y);
angle = atan2(dy, dx) + (45/PI);
player.SetRotation(-angle * 180 / PI );
This works not perfect, because for some reason the cursor is not in the middle of the sprite when I turn it to the left for example.
The code for the moving i use just looks like the following:
player.Move(-distance, 0);
So moving doesn´t do anything special yet.
The code I tried for moving in the cursor direction was the following:
float dY = sin(angle) * distance;
float dX = cos(angle) * distance;
this->player.Move(dX, dY);
where angle is the rotation of the player an distance the distance the sprite should move in the angle direction.
For a better understanding i also produced a little youtube video
I hope very much that someone can help me.
Thanks in advance,
Simon