Camera keeps going behind walls/floor

Hello, I’ve recently started my first 3D game in Unity, and I’m currently trying to set the camera, the position and rotation went just fine using some tutorials of talented people, but the camera keeps going through walls or the floor and I can’t find any solutions for this problem, so here I am at Unity Answers.

I’ve already tried casting a Raycast or Linecast between the character and camera, but when it detects an object that isn’t the player, it’ll just shoot the offset to the minimum, or make the camera have a seizure.

The camera rotates around a pivot, which is the child of the player.

If anyone knows a way to fix this, please let me know.

I look forward to your help!

found the solution myself, or atleast something that seems to work, I’ve sent 6 spherecasts with a radius of .1f into every direction (forward, backwards, left, right, up, down) and make the camera adjust itself to the point where there isn’t a solid object in the way anymore.