It looks like you're new here. If you want to get involved, click one of these buttons!
I am currently in the process of making a camera collision system. I was able to implement the part of bringing the camera to the hit position from a couple raycasts each leading from the camera's near view frustum corners. Surprisingly though, I am actually having quite some trouble with bring the camera back to it's original position.
The issue with just returning it to the original position after it isn't detecting collisions anymore is that it will go back, and then instantly be behind the wall again and try to go forward again, rinse and repeat.
I tried to counter this by sending a raycast behind the camera to the position it's trying to go to, and have it just go the position it hits (or if it doesn't hit anything, then it can go back to the original position).
This works for the most part, except for one issue. When the camera is right next to the corner of a game object, it sort of breaks. The camera will go forward in front of the object, but once it has, it is in a position where it doesn't see anything behind it. So it will go back to the original position, but then it sees the corner again and tries to go forward again!
I've tried a couple different things to counter this, such as only going back if it doesn't hit anything again, but it hasn't worked.
I've been on this for a bit, and have about reached the peak of my problem solving abilities. I may just be thinking too hard, but I can't think of a better solution to fix this issue. If anyone has any suggestions, they would be greatly appreciated.
Visualization for my current system. The square is the camera, the circle is the player, and the lines are the rays: