Unity Objects Clipping when too close to camera

Hi so I was trying to make a VR game and I figured out everything up to the controller model. I didn’t have one so I used a game object with a cube. Then applied a material then tested it. Everything was working until the cube will disappear when it is too close to the Main camera. Any solutions?

Here’s a picture

Have you tried reducing near clipping plane? Like to 0.2 or something - up to you exactly to what but if you haven’t, definitely worth a look.

This is a common thing for VR games to have because you cannot control where the user moves in real life, thus moving through bounds. In your case, the head camera is literally inside the objects in your scene (hands).

A few things that might help:

  • Open the Camera in the inspector and reduce the clipping plane “near” as close to zero as it will let you (0.01).
  • Shrink the cubes down to better match your hands in real life (so it’s impossible to put them through your head).

There is no need to worry about this much further than doing the above, however, the first solution is a really good way to prevent this without too much work::
Solutions:

  • Prevent head and object from intersecting: Unity has a built-in physics system that detects collisions between rigid bodies. To implement this, add a Collider to the main camera and add a collider and Rigidbody to the object. Then tick the box for “Is Kinematic” and untick the “Use Gravity”. In the case of the hands, you’ll probably experience lagging/jumping. This is because the box is trying to move to your hands but is constantly being pushed out by the head. There are ways to fix this but it can get complicated really fast depending on how clean you want it to be.
  • Object Culling: Disable the Renderer attached to the object when it gets close to the camera. This prevents you from “clipping through” the object but might make it look like the object is disappearing randomly. You can also fade the object away as it gets closer to the face but this can require setting up specific materials.
  • Screen space rendering: instead of normally rendering objects that might clip the camera, you can render them separately so they always render on top of the camera and never clip. This is extremely difficult to do in VR situations, and for the most part, won’t look good even if done perfectly. This is a mere hypothetical solution that is done to prevent this in non-VR games.

Let me know if you need any elaboration or want some resources to study the above topics.

3 Likes