2D Camera RPG

Hi, i tried to make a camera for a 2D game (an rpg) can follow the player and collide with the end of the map.
I tried jus drag and drop the camera inside the player, put some blocks at the edges of the map and putting a Box Collider on the camera. This works, but very glitchy, because when the camera collides with the block it seems like its bouncing and the player still walking to the edge (i wanted it) but when the player walks to the opposite side doesn’t come back to the center of the camera.
Any ideas?
(Sorry, i got a really bad english)

Instead of parenting the camera to the Player GameObject, you could add a script that constantly updates the position of the camera to be directly over the player, but within the bounds of a minimum and maximum world position, like so:

RPG2DCamera.cs

using UnityEngine;

public class RPG2DCamera : MonoBehaviour
{
    public Transform target; // set to the Player GameObject

    public Vector2 worldPosMin = new Vector2(-10f,-10f);
    public Vector2 worldPosMax = new Vector2(10f, 10f);

    void Update()
    {
        if (target != null)
        {
            Vector2 targetPos = target.transform.position;

            float x = Mathf.Clamp(targetPos.x, worldPosMin.x, worldPosMax.x);
            float y = Mathf.Clamp(targetPos.y, worldPosMin.y, worldPosMax.y);

            transform.position = new Vector3(x, y, transform.position.z);
        }
    }
}

Just add this script to the Camera and remember to set the Player as its Target in the inspector.