Skip to content Skip to sidebar Skip to footer

Why Are My Bullets Travelling At A 90 Degree Angle From The Mouse?

So I found a few answers online, and upon trying one, I discovered that the 'bullets' are always 90 degrees away from the cursor. Any way to fix this? I have very minimal experienc

Solution 1:

Because the calculation of the angle is wrong:

whileTrue:
    # [...]if key[pygame.K_SPACE]:
       # [...]#bullet.angle=math.atan2(mouse[0]-bullet.rect.x,mouse[1]-bullet.rect.y)
        bullet.angle = math.atan2(soldier.rect.y - mouse[1], mouse[0] - soldier.rect.x)
        
    #angle = math.atan2(mouse[0]-soldier.rect.x,mouse[1]-soldier.rect.y)/6.28*360
    angle = math.atan2(soldier.rect.y - mouse[1], mouse[0] - soldier.rect.x) * 180/math.pi

See How to know the angle between two points? and How to rotate an image(player) to the mouse direction?

Post a Comment for "Why Are My Bullets Travelling At A 90 Degree Angle From The Mouse?"