Camera collision in closed spaces

Just looking for some additional advice here. I have written a player follow camera without using orbitcontrols. Used spherical coordinate formulae to update the mouse position on mouse drag. I raycast to the expected position of the camera, and if intersection found, i update the camera’s position to the intersection position of the raycast.
Some code:

if (intersects.length) {
      const offsetVector = directionVector.multiplyScalar(-0.25);
      this.camera.position.copy(
        intersects[0].point.clone().add(offsetVector.clone())
      );
    }

However, this solution isn’t perfect. @mjurczyk if you do see this, would love to know where I can learn more about the fov based padding approach. I tried sphere collisions like you mentioned, but i suspect it performs well in closed spaces (small room glb files). When the mouse is moved fast, the backfaces of the intersected meshes still show.
Would love to learn more from you guys!

@VForsmann what solution worked best for you? @seanwasere any inputs that you might have?

Sorry, not a problem i’ve felt I really ever needed to solve.

I think how you solve it dependes a lot on how “closed” your space is.

In the above demo, I doubt the time and effort implementing it in this context, would really make any noticeable difference at all.

One approach that works decently well… is when you get a collision with the raycast… don’t use the collision point… use the point halfway between the target and the collision point.

Also… change the behavior if the collision is close or if there isn’t a collision.

If the camera needs to move closer, snap it in one frame…
This prevents frames of visible camera/wall intersection.

if its safe to move it back, then tween it back slowly.
This prevents a lot of the jitter you get in closed spaces with a raycast camera.

If you have a copy of GTA 5, its worth firing it up to see how they handle it. It’s similar to what I am describing.