How do I stop the camera from seeing inside meshes?

In my scene, the camera is positioned at the top of a capsule. When I get too close to another mesh, the camera can see inside it, and it looks very glitchy. How do I stop this from happening? I tried increasing the size of the player’s impostor, but that doesn’t allow the player to get into gaps that the player should be able to get into easily.

playground - https://playground.babylonjs.com/#50EU7Y#1

It is not easy to see anything in your example :slight_smile:
But seems that you just forgot to include this line in your code:

scene.collisionsEnabled = true;
1 Like

Also more slowly, but perhaps better solution - check bounding box or mesh intersection for capsule and scene actors (items). If intersect is true, we can change mask for mesh or disable mesh or assign not renderable material or try to change render method for Mesh (i’m no sure about this).
It depends of you needs.

1 Like

It is possible but there is already built-in function, one just need to use it properly - Camera Collisions | Babylon.js Documentation

1 Like

The capsule I’m using is a physics impostor, so adding this line doesn’t really change anything

I don’t understand what you mean.

Sorry I wasn’t clear enough, but what I mean is that when the camera gets too close to a mesh (not inside a mesh, then it seems to cut off a part of the mesh. This is what I mean:
mesh when the camera is too close -


mesh when the camera is a bit farther away -
image

If you still don’t get it, try moving close to the green box in the scene, and moving away from it in this playground - https://playground.babylonjs.com/#50EU7Y#3

That’s what I see in your scene; what do you mean with the word “moving” and what should one move?
(I couldn’t move anything in your 1st example, but can move when collisionsEnabled)

Does the example from Documentation works as you need? - Babylon.js Playground

Maybe you need to define collision radius? As example:
camera.collisionRadius = new BABYLON.Vector3(1.5, 1.5, 1.5);

the player - wasd controls

In this playground - https://playground.babylonjs.com/#4HUQQ#1034, look around using the mouse. You can see that part of the box seems to disappear, which makes the whole thing look glitchy.

The same thing is happening in my playground too.

Hey, perhaps for camera setted up big nearClipping?
You tune minZ property for camera?

5 Likes

It works, thanks a lot.

2 Likes

camera.minZ = 0;

Works like a charm, :wink:.

2 Likes

Yeah