Help with grounding: Linecast results too narrow.

Disclaimer:

Hello, this is my first post, so it is possible that I am not being accurate in many ways, such as the forum threads. If that is the case, please accept my apologies. I come from Game Maker, where I developed a point and click adventure and now I am triying to prototype a metroidvania game in Unity3D.

The problem:

This method allows me to calculate when my character’s sprite is grounded by casting a ray from its center, but as it is only a 1px ray, it fails to accurately validate the jump when my character is in the very edge, thus resulting in poor control when it is near the borders:

grounded = Physics2D.Linecast (transform.position, groundCheck.position, 
1 << LayerMask.NameToLayer ("Ground"));

I have been thinking about throwing 2 linecasts:

1 from: (center + sprite_width/2)

Another 1 from: (center - sprite_width/2)

But since there can be a situation where I stay on a very narrow platform this could not work either.

Here I show an image of my character, not grounded, although it should:
1610006--97762--$Linecast_centerOnly.png

Any indea/s? Thank you very much for reading untill this point.

1610006--97760--$Linecast_centerOnly.png

I have pretty much the same problem. Worked around it for the present. A fatter ray would be welcome!

If you expect to be standing on very thin objects, then what you may want instead is OverlapAreaNonAlloc:

This will essentially create a box between two defined points that it will “raycast” inside of, in a sense.

Another solution would be to create a third ray that starts from one corner of your character, and goes to the other corner, but on an angle lower down away from it. This way you have a single ray taking care of the whole bottom. (such a solution would still require 2 other raycasts on each corner, if you’re using edge-colliders for ground)