- Home /
How do I prevent my camera from looking through objects?
Hello,
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.
Answer by AngryAnt · Mar 18, 2010 at 10:41 AM
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.
Thanks,
Avoid the Object should be hard, because its in a house.
How to make your step 2?
If you look at the camera component, you'll see a "near clip plane" value. Try adjusting this and notice how the camera gizmo changes in the scene view. The line near the camera position represents the position of the near clip plane. Switch to top view and make sure that this line is well inside the border of your collider by either expanding the collider or decreasing the near clip plane. The former is preferable.
Answer by runevision · Mar 18, 2010 at 10:42 AM
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.
Adding a Collider Component to the $$anonymous$$ain Camera fixed the problem for me.