- Home /
Near plane clipping by object
Hi, I was wondering if there was a way to make the unity camera's near clip plane clip by object and not by "faces".
Our reasoning for this is that we want to create a 2.5D platformer where the player can look at the level in the distance and it seems normal to him. However, upon reaching the actual area, he is only able to see objects between the far plane and the near plane of the camera, so his view of the character isn't obstructed. Due to the way near clipping works however, some of those "hidden" object's geometry can very easily show up. Ideally we want unity to simply not draw objects that have any vertices between the near clip plane and the camera.
Hopefully this image should help someone understand this better: the selected corridor is not meant to be shown as the player moves through this corridor, only after he leaves it. However, if we tilt the camera in a certain way, bits of it's geometry can pop up unwantedly during gameplay.
Answer by ScroodgeM · Aug 18, 2012 at 08:26 PM
solution 1 - trigger
make s trigger in front of camera. trigger should be attached to camera GameObject to move with it. size and position of trigger should be from camera to player zone to be covered. disable renderers of all objects that comes to trigger, enable again on exit. playing with different trigger forms and sizes can solve your issue
solution 2 - calculations
like solution 1, but use simple calculations. for example, checking distance from camera to object and comparing it with conditions to disable or enable.
solution 3 - shader clip
shader can clip drawing too. in shader you can make a clip plane effect, but the clip plane can be any, not only perpendicular to camera's view
http://docs.unity3d.com/Documentation/Components/SL-SurfaceShaderExamples.html (search for slices word)
solution 4 - spherecast
spherecast will return you all objects that are placed in some space, for example in space between camera and player. get it and disable
Answer by Dragonlance · Aug 18, 2012 at 08:44 PM
Maybe you should try to not let that happen by having more camera control, or you will end up with performance leeching "having everything in colision boxes" or custom shaders for everything.
I am sure you can find an exiting looking camera drive for this situation.
That's something we're worried about right now as we're currently using "building blocks", each with their own mesh collision, to create levels as we still haven't found a better method. We're currently trying to limit this by using layers.