0

My bullets do move in the direction of where I clicked which is great until it stops there and doesn't move any further.

if ev.type == pygame.MOUSEBUTTONDOWN:
    mousePos=pygame.mouse.get_pos()
    bulletDestination.append(mousePos) #where I clicked
    bullet=[knightPos[0]+63,knightPos[1]+27,20,20] #Position of the center of my player
    bullets.append(bullet)

for i in range(0,len(bullets),1):
    angle3=math.atan2(bulletDestination[i][1]-bullets[i][1],bulletDestination[i][0]-bullets[i][0])
    bulletDeltax= math.cos(angle3)*bulletSpeed
    bulletDeltay= math.sin(angle3)*bulletSpeed
    bullets[i][0]+=(bulletDeltax)
    bullets[i][1]+=(bulletDeltay)
    pygame.draw.rect(mainSurface, rectColor3,bullets[i])
Henry Woody
  • 14,024
  • 7
  • 39
  • 56
  • If the bullet moves beyond its target, the value you calculate for `angle3` will take it back in the opposite direction You need to calculate the angle *once*, when the bullet is initially fired, and use that for all further position updates. – jasonharper Jan 08 '23 at 23:15

0 Answers0