How do I prevent my camera from looking through objects?


Im using first person camera. When I go near an object, I can look trough the Object.

How can I prevent it?

Thank you very much.

Well you have a few options:

  • Make sure the camera avoids the object (commonly used for third person cameras).
  • Adjust the position of the camera and the near clip plane relatively to your character collider to ensure collision happens well before any object intersects with the near clip plane.
  • Render the objects close enough to the camera to be trouble as semi-transparent or even disable their rendering completely.

The camera can look through objects because they are closer to the camera position than the camera near clip plane.

You can decrease the near clip plane, but keep it as big as you can, since you may get more rendering precision errors the lower you set it. (Also keep the far clip plane as small as you can, for the same reason.)

Alternatively you can try to prevent that the camera ever gets that close to objects. You could increase the radius of the capsule collider on your character, or if it's placed somehow a bit in front of the center, you could move it a bit back.