The task is to determine whether any itty bitty part of an object’s collider lay within a Rect on the screen.
Currently, my jury-rigged solution is to do a ray cast out from the center of the Rect to wherever on the 3D terrain it hits and for each object, find its Collider.ClosestPointOnBounds() to the hit point, project that point back to screen space, and then test if it lay within the rect. This works over 90% of the time, but there would be some cases where it would be off, like if it’s an FPS and the ray hit a very distant or very close wall. In that case the ClosestPointOnBounds would appear more to the center of the object relative to the camera, and if the Rect’s side was between this point and the collider’s far edge, it wouldn’t catch it. Not to mention, it seems clumsy to go casting a ray and doing all these 3D calculations just to bring it all back to 2D again.
I’d imagine that this is a relatively common task, and that there’s a more clean-cut way to do it. Since Unity has already written a Collider.ClosestPointOnBounds method for 3D space, I would reckon it to be both simpler and less cpu-intensive to calculate it in 2D.
Thus my question is, how can one project an entire collider into 2D first, and then find the closest point of that 2D shape to a given point, or otherwise generally determine if the collider is at least partially within a bounding screen Rect?