Unable to get height difference at a certain angle

We are currently trying to building a gizmo that lets the user scale the box model. Our approach has it perfectly running for scaling length and breadth. We have also mostly made it scale for the height as well except for certain scenarios.

I referenced this earlier post on how to get the height vertically

I’ve recreated the issue in the sandcastle
Sandcastle link

If you move the mouse cursor above the box entity at the default angle and camera position the console will show the value in the console increasing which is how it should be.

However, if you rotate the camera 180 degree around the box and tilt the camera way up. If you move the mouse above the entity will show decrease it value and go into the negatives.

Any advice on how to fix this would be appreciated.