Bouncy/repelling boundaries for a 2D shooter

So I’ve managed to create a boundary for my player by placing cuboid colliders outside of the bounds of the screen and setting them to have a bounciness of 0.4. This kind of works in that when the players hits it at a relatively high speed it is bounced back, but when the player hits it at a low speed it will scrape along the box weirdly.

I guess what I want is the edges to produce some kind of force that gets stronger the closer to the edge you get until the player can’t overcome it, but I really have not the slightest clue how to do this.

I’m scripting in c# if scripting is needed. Any ideas?

You could place a trigger on the barriers that detects when the player is near, and then use

OnTriggerStay(Collider other)

to check how far the player is from the edge of the wall, and do

other.gameObject.GetComponent<Rigidbody>().AddForce(vectorAwayFromWall / distanceFromWall)

The closer they get to the wall, the harder the push to move them away from the wall.