- Home /
CalculateFrustunPlanes / TestPlanesAABB returns unexpected results
I'm trying to figure out how to bind a camera to a viewable area.
The camera is orthographic and rotated to (30,45,0) for an isometric view.
The camera is a child of an unscaled gameobject with no rotation (this parent is used to control position easily).
When I generate planes using the manual's example of CalculateFrustumPlanes, the planes are all over the place.
I need the functionality to work with different orthographic sizes as that will be used to zoom the camera.
If I use the below code to check if a collider is within the frustum I get erroneous results (see image).
bool doOnce = true;
public Collider[] toDetect;
private Plane[] planes;
string detected = "";
void HandlePanBounds()
{
if (doOnce)
{
doOnce = false;
/*
int i = 0;
while (i < planes.Length)
{
GameObject p = GameObject.CreatePrimitive(PrimitiveType.Plane);
p.name = "Plane " + i.ToString();
p.transform.position = -planes[i].normal * planes[i].distance;
p.transform.rotation = Quaternion.FromToRotation(Vector3.up, planes[i].normal);
i++;
}
*/
}
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
detected = "nothing";
for (int i = 0; i < toDetect.Length; i++)
{
if (GeometryUtility.TestPlanesAABB(planes, toDetect[i].bounds))
{
detected = toDetect[i].gameObject.name;
}
}
}
void OnGUI()
{
GUI.Box(new Rect(0, 0, 100, 100), "Detected: " + detected);
}
HandlePanBounds() is called in Update().

All help is appreciated. I've Googled this and tried a variety of answers for the past 2+ hours and they aren't getting me anywhere.
Well, I've found out that the issue may lie in how I'm using TestPlanesAABB. I'm trying to detect a somewhat large collider (Size is (100,1,2100). If I make that collider less than 100 units the detection seems O$$anonymous$$. Not ideal though and I'm not 100% sure this is the issue. I also noticed an error in my visual representation of the planes. They now show in the correct locations, but the TestPlanesAABB issue still persists. I will likely be looking in to just doing a raycast from the camera's bounds when I can figure that out. Tips on that are welcome.
Your answer