Question

I am making a game with pygame and i want the player the face the cross hair, this is the code I have, I made it print out the angle in my idle and I noticed that the angles where all wrong and the player didnt rotate at all anyway. I've seen some other questions like this and I've followed them but i still get the wrong angle and the image dosnt rotate anyway

here is my code for the angle and rotating image:

mouse_x, mouse_y = pygame.mouse.get_pos()
mouse_x -= crosshair.get_width() / 2
mouse_y -= crosshair.get_height() / 2
player_atan = math.atan2(player_x-player_y, mouse_x-mouse_y)
player_angle = degrees(player_atan)
pygame.transform.rotate(screen, player_angle)
Was it helpful?

Solution 2

You should check out the python docs: it has some valuable info.

The reason why your sprite does not rotate is because rotate returns a new rotated surface.

A link to the docs:docs

OTHER TIPS

You have to subtract the same components from the different points.

player_atan = math.atan2(mouse_y - player_y, mouse_x - player_x)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top