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.

2 Answers

2

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?

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