- Home /
Detecting when camera's near clip plane is hit
Is there a (elegant) way to detect when the camera's near clip plane is hit or when culling starts?
current solution: kinematic rigidbody trigger box at nearclip plane, ontriggerenter()
If you need actual 3D collision detection, your method is superior to any alternative I can think of. You could pull off certain aspects with a fancy raycasting solution, but there's not a way to emulate full 3D collider-based detection without actually having one in the scene. As far as I know.
Answer by VesuvianPrime · Sep 25, 2014 at 02:39 PM
One way of testing to see if something is visible by the camera is to do the following:
Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(camera);
if (!GeometryUtility.TestPlanesAABB(frustumPlanes, bounds));
Debug.Log("Not visible!");
You could reduce the frustumPlanes array to only contain the near plane.
Do you know if this is true if only part of the object is occluded?
Answer by TheDDestroyer12 · Sep 25, 2014 at 02:43 PM
Your current solution is the best I can think of. If you have a script on the camera, you can also set the scale of the collider to be the same as the cameras near clip plane multiplied by two in the start function, to make them match exactly if you wan't to.
Good luck!
/TheDDestroyer12
Your answer
Follow this Question
Related Questions
Making particles the only render on a camera? 1 Answer
Raycast hitting objects to the left of my player 1 Answer
Two Levels of Directional Lighting For Different Cameras 1 Answer
Collider and raycast hit is not working properly 1 Answer
How do I get my camera to render 2 culling masks in scripts? 2 Answers