I'm trying to find a way to have enemies track the player in my 2d game (pygame) but not clump up
Currently, when I shoot at them, the bullet collides into and damages all of the enemies that are clumped. I would like it to be a hoard but spread out just enough to where I can't hit every single enemy at once
I'm not sure how I would get the individual values of the enemies' positions so I can move them when they collide or how I should move them
This is what I currently have for the enemies to track the player:
for aliveEnemies in enemy:
if playerObj.rect.x - aliveEnemies.rect.x != 0:
if playerObj.rect.x > aliveEnemies.rect.x:
aliveEnemies.rect.x += 1
if playerObj.rect.x < aliveEnemies.rect.x:
aliveEnemies.rect.x -= 1
if playerObj.rect.y - aliveEnemies.rect.y != 0:
if playerObj.rect.y > aliveEnemies.rect.y:
aliveEnemies.rect.y += 1
if playerObj.rect.y < aliveEnemies.rect.y:
aliveEnemies.rect.y -= 1"
Any help or points in the right direction would be greatly appreciated