How to stop enemies to go into each other?

hey guys, I am pretty new to Unity and tried to make a little game. There I made a quick Skript for an Enemy that is chasing the player. Thats the SKript I used:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class EnemyChaseSkript : MonoBehaviour { public GameObject target; public float ChaseSpeed;

 // Update is called once per frame
 void Update()
 {
     transform.position = Vector2.MoveTowards(transform.position, target.transform.position, ChaseSpeed *Time.deltaTime);
 }

}

Now I want to have two of these Enemies. I dupplicated them and both followed me. But here is the problem. After a few Seconds they just go into each other. I dont now how to stop them going into each other. I added a 2D Collider and 2D Rigidbodies but nothing helped and i couldnt find anything about it in the Internet. I hope you can help me :slight_smile:

The way you are moving them is probably forcing one into the other. Add a force to the rigidbody you added instead:

Rigidbody2D enemyRb;
// Mess around with this variable in the editor until you find a speed that you like
public float speed;
// Assign the player to this variable in the editor
public GameObject player;

void Start()
{
    enemyRb = GetComponent<Rigidbody2D>();
}

void Update()
{
    // .normalized is there to make the enemy's speed always the same, it returns the Vector2 with a magnitude of 1
    enemyRb.AddForce((player.transform.position - transform.position).normalized * speed);
}