How to make player bounce back on collision?

I have a top-down view scene with player and game object (duplicate of player but without script).
Player is controlled with the script. When player collides with the game object, game object bouncing back, but when it hits the player on the bounce player doesn’t bounce back. How do I make the player bounce back on collision too?
Here’s my script:

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

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody2D rb;
    public float speed = 5f;
    Vector2 movement;
    public GameObject Enemy;


    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        movement.x = Input.GetAxis("Horizontal");
        movement.y = Input.GetAxis("Vertical");

        rb.MovePosition(rb.position + movement * speed * Time.fixedDeltaTime);
    }

First: I don’t see any code here for any bouncing. If you attached a physics material to the player and are relying on it to provide the bounce- that’s your problem. On the fixed update the “bounce” will be “overridden” by the code in your fixed update - since you are directly assigning a position to the rigidbody. So- you need to add collision detection function that temporarily turns off this assignment. Create a variable, say, ‘isBouncing’ and default it to false. Whenever the player collides set ‘isBouncing’ to true. Then modify your fixed update:

 void FixedUpdate()
 {
     movement.x = Input.GetAxis("Horizontal");
     movement.y = Input.GetAxis("Vertical");

     if(!isBouncing) rb.MovePosition(rb.position + movement * speed * Time.fixedDeltaTime);
 }

However, it would probably be better to assign the bounce directly when a collision is detected. In your OnCollision function get the normal and apply a force to the rigidbody of the player in the direction of the normal (I think it’s ContactPoint.Normal ) You would also use the 'isBouncing" variable to make sure any force applied isn’t immediately cancelled out. Your additional code might look like this:

void OnCollisionEnter2D(Collision2D collision)
{
    if( /*code here to make sure the collision is with the object in question */ )
    {
        float bounce = 6f; //amount of force to apply
        rb.AddForce(collision.contacts[0].normal * bounce);
        isBouncing = true;
        Invoke("StopBounce", 0.3f);
    }
}

void StopBounce()
{
    isBouncing = false;
}