Enemy Knockback when hit player 2D Topdown

I I have a 2D topdown game and what I want to happen is that when an enemy hits a player that it was following, it gets knocked back for a sec, so that the enemy isn’t constantly hitting the player. Here is my script for moving the enemy

public float speedMax;

private float speed;
private Rigidbody2D rb2D;
private Transform target;

void Start()
{
    speed = speedMax;
    rb2D = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update () {

    target = GameObject.Find("Player").transform;

    rb2D.MovePosition(Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime));        

}

So what I want to know is how to I make the enemy move back a little when it hits the player, stop for less than a second than follow the player again. Almost like if a ball trying to go through a wall but when it gets hit it just bounces back and then goes forward again. Thanks for any help

I would suggest maybe a small box collider and look into OnTriggerEnter or OnCollisionEnter? Something like addforce to the enemy rigidbody2d will work depending on your implementation.

P.S. You should declare the target in the Start function once, not every frame in Update…

Hope this helps get you started. Good luck.