Edge Collider 2D often doesn't get detected [2D platformer]

This is about a 2D platformer. My character doesn’t detect the ground below him, at least he doesn’t 99% of the time. The collider on the ground is an Edge Collider, which I use to get slopes. But most often he can’t detect the ground, so he can’t jump.

He has a child object, a GroundCheck, which checks if there is a collider in the ground layer within a small radius. I’ve tweaked with the radius, but it’s either too low (which makes him unable to see the ground thus it makes him unable to jump), or too high (which enables him to jump all the time, even in the air).

Is there a bug in Edge Collider 2D? Should I use a Polygon Collider 2D instead? I don’t think providing any code is neccessary but if it is, I can edit this.

I was also trying to do something similar to what you explained with little to no success. So I thought I’d check out what the Unity 2D tutorial had for its ground collision code.

I found this:

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

which worked much better than the OverlapCircle I was previously trying to use. Essentially when using Linecast, a line is drawn between the ground check’s position and the position of the character and if it crosses a collision line (edge collider 2D which is on the Ground layer) it will set grounded to true.

Hope that helps.

I know this is old, but Unity’s ‘solution’ unfortunately doesn’t take into account slopes or wide characters’ collision boxes where jumping before a gap is required to be precise (i.e. almost ALL platformers).

It would be possible using 1 wide raycast/linecast at the player’s feet (instead of 3 (or more) tiny ones) to expand across your character’s bbox width (such a check would be mandatory with any varied/bumpy terrain). The problem with this method is that a horizontal raycast/linecast does NOT collide with parallel edge colliders at the moment.

Anyone want to beg Unity for this simple feature to be included? If so, you’d save CPU that you’d have to waste on boxes or overlapping circles when a simple ray/line would have done just fine.