Camera Collision works, but still sees through wall

I have a diagram below of a situation that can occur with a camera collision script:

As you can see in the diagram, the camera properly repositions itself so it doesn’t go through the wall, but the edge of the screen pokes past the wall. Now, there are three obvious options I can take to fix this. One is to calculate the angle between the camera and the wall and then scale the camera’s field of view to fit in the angle. This will work in many cases, but it may result in strange, distorted images. The second option is to move the camera closer to the player after positioning it at the wall; however, there is no guarantee that the camera will be in a good spot. The third option, which I am going to try, is to move the camera a little bit closer to the player (to escape contact with the wall), cast two rays (one going left, one going right), and determine if the left or right side is hitting a wall, after which I will shift the camera left or right.

I’m going to try to solve this problem myself, but if anyone has any ideas, it’d be nice to read them.

Use a sphere cast from the player to the desired camera position, and position it at either the hit location or the desired position. You can also decrease the camera’s near clipping distance to allow for it to get closer.

Like Darkcoder said, I would reduce the cameras minimum clipping distance to the smallest possible value (0.01, I believe), or maybe just put a sphere or capsule collider on the camera to prevent it from getting too close to the wall?