My question is fairly basic. What I am trying to do is make a gun (basically a rectangle) with the top corner of the gun centered at the center of the player. I also want to have said gun rotate around that center point. I have tried several things, and I have managed to spawn the gun and make it follow the player.
My problem lies in rotating the gun. If I use pygame.transform.rotate on the original image, my gun seems to squish and the rectangle does not seem to rotate but just changes sizes. I already know how to calculate the angle and my current code is down below:
gun_rect.x=player_rect.x
gun_rect.y=player_rect.y
gun_rect.width=30
gun_rect.height=20
mouse_x, mouse_y = pygame.mouse.get_pos()
rel_x, rel_y=mouse_x-gun_rect.x,mouse_y-gun_rect.y
angle=(180/math.pi)*-math.atan2(rel_y,rel_x)
print(angle)
gun_surf1=pygame.transform.rotate(gun_surf,int(angle))
Gun rect is a rectangle and gun surf is the graphic for the gun that I want to rotate.
Thank you very much I have provided some screenshots below: