So, In my game, I have enemies that will follow you using the angle between the player and the enemy. Often the enemies will get bunched up and follow the same path, like so:
From this
Over time to this (It is really the 4 different enemies you saw in the first pic touched into the same spot, since they follow me by the same angle…)
The Code:
// Get differences from player to enemy.
Player target = World.getPlayer();
float dx = target.x - x;
float dy = target.y - y;
float dist = (float) Math.sqrt((dx * dx) + (dy * dy));
rot = MTrig.atan2(dx, dy);
// Just to make sure it stops before it gets too close to me.
if (dist <= MUNCHING_DISTANCE) {
return;
}
// Move according to the angle
move(MTrig.cos(rot) * speed, MTrig.sin(rot) * speed, delta);
What I want is to make sure they do not bunch up into ‘one enemy’ like that.
Thanks!
EDIT:
Oh, and I know what the problem is caused by… They are running on identical algorithms. I want to know what I should do to solve it.