Skip to content Skip to sidebar Skip to footer

How Can I Make My Enemys Projectile Attack The Player Where Ever The Player Moves?

I have an enemy that shoots projectiles but only shoots to the right I want it to shoot at the player with any position I don't know how to do that heres a vid what I have done so

Solution 1:

Looking at your script didn't help me a lot as you are maintaining many different classes.

for shootss in shootsright:ifshootss.x<500andshootss.x>0:shootss.x+=7

Here it appears that when you are updating your bullets x coordinate you are incrementing it with a positive constant value.

And then you update it like this in your bullet class.

   window.blit(self.ksud,self.rect)

What you can do instead is have a bullet speed that changes its direction.You can use a code like this

ifobject_you_want_to_follow.x>object_shooting_the_bullet.x:bulletSpeed=+7elifobject_you_want_to_follow.x<object_shooting_the_bullet.x:bulletSpeed=-7

Same applies if you want to follow it vertically along the y direction.

OPTIMIZATION TIP

From what i understand having this in your bullet class makes no difference as you are updating it soon after.

window.blit(self.ksud, player_rect)

EDIT

To make things easier you can simply do this

   for shootss in shootsright:
       if shootss.x < 500 and shootss.x > 0:
           if enemy.x < playerman.x:
               shootss.x += 7
           else:
               shootss.x -= 7
       else:
           shootsright.pop(shootsright.index(shootss))
   if len(shootsright) < 1:
           shootsright.append(Bools(round(enemyshoots1.x+enemyshoots1.width-107),round(enemyshoots1.y + enemyshoots1.height-50),(0,0,0)))

Post a Comment for "How Can I Make My Enemys Projectile Attack The Player Where Ever The Player Moves?"