1

Question: How can I make a bullet move towards a target without following the target using Pgzhelper in Pygame Zero?

I wanted to share this with a lot of people that may have the same trouble using Pygame Zero:

The problem may stem from people confusing how to move Actors using angle(), distance(), direction(), direction_to(), move_forward(), move_backward(), move_towards() and so on. I've watched and read a lot of videos and read many formulaic solutions but did not understand the key points of them because I suck hard at basic trigonometry.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

So here's a simple solution, I realize after a few days:

ammo = []
def reload():
    bullet = Actor('pic', center = (x,y))
    bullet.angle = bullet.direction_to(target)
    ammo.append(bullet)

def update():
    for bullet in ammo:
        bullet.move_forward(15)
        if bullet.x < 0 or bullet.x > WIDTH or bullet.x < 0 or bullet.y > HEIGHT:
             ammo.remove(bullet)

And after realizing this I LOL myself for how simple the solution was. Hahaha XD I hope this would help others that suck at Trig or Math like me and are searching for simple ways to program games "as efficiently as possible".

  • Thank you very much to the Admin or whoever corrected my grammar mistakes. I really appreciate it and I hope this would make my post reach and help a lot more people. :) – AIzen Vermillion Sep 28 '22 at 04:55