[英]finding the angle between to points with pygame
我正在用pygame制作游戲,我想讓玩家面對十字准線,這是我的代碼,我在閑置狀態下打印出了角度,我注意到錯誤的角度和玩家沒有旋轉的角度無論如何。 我看過其他一些這樣的問題,但我也遵循了這些問題,但我仍然得到了錯誤的角度,並且圖像始終不旋轉
這是我的角度和旋轉圖像代碼:
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)
您必須從不同的點減去相同的分量。
player_atan = math.atan2(mouse_y - player_y, mouse_x - player_x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.