Basically. I am trying to make a tower defense game and I need the towers to shoot at the enemy and for the bullet to follow that enemy at a certain speed until they hit it. I have already written all the code however I, for some reason, cannot get the 'tracking' method to work for the bullet. I thought I could do this simply by using polar to cartesian conversions however I must be over looking something as the bullet does not go anywhere near its target.
This is what I have:
def follow(self):
dx = (self.rect.x + 4) - (self.target.rect.x + 15)
dy = (self.rect.y + 4) - (self.target.rect.y + 15)
angle = math.atan2(dy, dx)
x = self.speed * math.cos(angle)
y = self.speed * math.sin(angle)
self.rect.x += x
self.rect.y += y