For a visual effect I’m working on, I need an orthographic camera triggered by a box collider. To do that, I would like the box collider to be perfectly lined up with the Camera’s viewing box, so that any object that enters the camera’s view will turn the camera on. When everything is oriented at a rotation of (0, 0, 0), my code works great. But modifying the X and Z components of a rotation causes the box collider to be slightly misaligned.
For the visual effect, the camera is always looking at a planar mesh, so I can use the bounds of the plane to get the X and Z bounds of collider. The Y value is what I’m struggling with. Also worth mentioning is that the box colliders are being set up programatically to get them as lined up as possible.
Here’s the relevant code:
private void Start()
{
SRTP = transform.GetChild(0).GetComponent<SnowRenderTexturePipeline>();
Bounds meshLocalBounds = transform.parent.GetComponent<MeshFilter>().sharedMesh.bounds;
Bounds meshWorldBounds = transform.parent.GetComponent<MeshRenderer>().bounds;
float colliderHeight = SRTP.groundCam.farClipPlane;
boxCollider = GetComponent<BoxCollider>();
boxCollider.center = new Vector3(0, meshWorldBounds.center.y - transform.parent.position.y + SRTP.displacement / 2f, 0);
boxCollider.size = new Vector3(meshLocalBounds.extents.x * 2f, colliderHeight, meshLocalBounds.extents.z * 2f);
SRTP.SetActive(true);
objectCam = transform.GetChild(0).GetComponent<Camera>();
objectCam.Render();
groundCam = transform.GetChild(1).GetComponent<Camera>();
groundCam.Render();
}
Here’s some pictures illustrating the problem:
Perfectly aligned with no rotation:

Misaligned with rotation:
