In Physics.BoxCastAll, how is the distance property of the returned RaycastHit array items calculated?

I think I’d have a difficult time describing what I mean in words, so I’m going to use visual aids. Sorry in advance for my poor drawings.

Lets assume we’re viewing a BoxCastAll (blue) from the side. As it moves “downward” from its center (orange) it determines a RaycastHit with a specific point (purple).

My question is how the “distance” property is calculated. Would the distance of RaycastHit be more properly represented by the pink line or the green line? Pink is a straight line between the point of the RaycastHit and the center of the BoxCast, while green is the vertical component of the pink line (assuming that the direction property of the BoxCastAll function is our reference for verticality).

I hope I phrased this well, and that I’m not making a duplicate question. I couldn’t find a post asking this question, but that may be because I don’t know how to phrase it properly. I genuinely appreciate any help anyone may have.

The hit distance will not be the distance to the object hit, but the distance the box had to travel before it hit anything. I’ve created a tool to help visualise it:


The box is cast from the yellow cube, and hits the blue sphere. The red line coming from the yellow box shows the hit distance. You can see that the hit distance is the distance from the origin, to the centre of the box at the position it hit the blue cube.


If you’d like to experiment with the visualizer script, you can download it from my github. It allows you to play with all the ray/box cast options and see the results as above and as values in the inspector:
206955-capture2.png