Collision on a 3rd Person Camera

A little while ago it was my task to create a Third-Person-Controller. I have not really gotten into it myself at the time, but I wanted to do it properly. And I have quickly realized that the camera is gonna be the part I'll work on the most. The movement itself was not too difficult. 


Getting the camera to not clip through walls was difficult. Especially because I wanted the camera to "understand" when it has to go in front of an object and when not (for example a pole is allowed to be between camera and player.)

The idea

The first thing I have tried is shooting a RayCast from the CameraCenter to the Camera. If it hits anything before the camera, the camera will get set to the hitpoint.
Unfortunately half of the near clipping plane will go through the wall, because it will only check the exact middle point of the camera.

The Solution

It took quite some time, but even­tually I came up with check­ing the four corner points the way you see it in the gif below. The shor­test is high­light­ed in blue. Except if there is no shor­test. Then all points are con­sidered the "shor­test".