Preventing Enemy Clumping

T

TriiiKill

Guest
I have multiple enemies that follow the player when he gets close, but they clump up into a tiny ball after chasing him for a couple seconds.

Anyone have a way to prevent them from getting so close to one another?

note:
-I don't want to make them solid or use collision events that prevent them from moving.
 
L

Luto

Guest
maybe could be this. imagining that you have your enemy and player offset in the center of a 32x32px mask collider.
////in enemy object
////in step event
if (enemy.x + 16) > (player.x - 16) //for RIGHT movement of the enemy
{
enemy.x-=1;
}
if (enemy.x - 16) < (player.x + 16)//for LEFT movement of the enemy
{
enemy.x+=1;
}
for the y axis is almost the same
 
T

TriiiKill

Guest
maybe could be this. imagining that you have your enemy and player offset in the center of a 32x32px mask collider.
////in enemy object
////in step event
if (enemy.x + 16) > (player.x - 16) //for RIGHT movement of the enemy
{
enemy.x-=1;
}
if (enemy.x - 16) < (player.x + 16)//for LEFT movement of the enemy
{
enemy.x+=1;
}
for the y axis is almost the same
Oh no, I don't mind them overlapping the player, I just don't want them overlapping each other.
 
T

TriiiKill

Guest
Never mind. I figured out what to do.

Collision Enemy with Enemy:
if other.x >= x
x -= 1

if other.y >= y
y -= 1

if other.x <= x
x += 1

if other.y <= y
y += 1

It works well, if anyone has a better solution, feel free to jot it down.
 
Top