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.