Camera Collision with Wall

Hey guys, so i’m trying to fix a problem where my camera would rotate and go through the wall. I thought i can stop it by just using a sphere collider. I would kind of work, but with enough speed it go right through it. I also wanted it so that when it does collide it would move the camera closer. Any idea how I can achieve this?

Add a static Rigidbody along with the collider for it to work.