I understand this BoxCast as an invisible box that has the same dimensions as the box collider of this object, but it’s moved down by a tiny bit (the .1fdistance argument)
By positioning it like this we can detect if something collides with our object at the bottom, but not on the sides or top.
This is how I visualize it in my head (notice the 2 lines at the bottom of the right image). Is my understanding correct?
You define a shape, and then it is cast forwards. Its shape and path will define a volume that will be used for overlap test. Documentation says this: “A BoxCast is conceptually like dragging a box through the Scene in a particular direction”. So it can be used for detecting a collision. It returns the first hit. Then there is BoxCastAll which returns all the colliders colliding with the volume created by cast box - AFAIK.
Check this video. I remember watching this a while back and it had pretty nice visualization which shows how box cast works:
“From what I understand it looks like my visualization is correct.”
Pretty much. Although…
“an invisible box that has the same dimensions as the box collider of this object”
This isn’t exactly true. You can define the size and rotation as you wish, it is not tied to your collider, although you can make it the size of your collider. There is Collider2D.Cast which casts your collider.
A box cast is unnecessary for ground checks with a contact filter setup. Check out this post from @MelvMay that uses a contact filter for an extremely simple ground check that works awesome.