RaycastAll doesn't pick up all collisions

Hey all, this is probably going to be a simple solution and I will hate myself for it, but for the LIFE of me I cannot figure out what I am doing wrong here. Recently I have been writing my own gravity system(as you do) and it is based on raycasts going down.

I’m fairly sure this isn’t a case for the scripting section as it has to do with 2D colliders.

Here is the method in question :

	bool IsGrounded()
	{
		RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position,-transform.up,0.6f);


		Debug.Log (hits.Length);
		Debug.DrawRay(transform.position,-transform.up,Color.red,0.6f);


		if(hits.Length>1)
		   {return true;}
		return false;
	}

Basically all I am doing is checking if it collides with more than itself then it will stop applying gravity

Here is the result
1491548--83277--$Raycast.JPG

Thanks for any help you may give everyone
Myhi

Thoughts:

  • What is the collider in question? Can you narrow it down to not detecting certain types of coliders? I’ve read of some possible detection bugs against Edge and Polygon colliders.

  • Why not do a simple Raycast and exclude the player’s layer instead of a RaycastAll? Seeing as all you are looking for is any hit within a certain range. Or, even simpler, detect via OnCollisionStay and filter by collision position (so you know it’s the bottom of your character colliding).

  • Your screenshot doesn’t actually show the problem occurring, just the DrawRay in action. I think we probably need more information as to what the problem is and exactly in what circumstances it occurs.

-Edge Collider yes.

  • Due to multiple players they must be able to land ontop of accurately, therefore layering will not work. That second part, raycasting is there in order to determine the “center” of gravity and since it has no central vertice, it will most likely have to stay a single raycast

-Crap sorry, swear I posted the debug log, my bad. Basically in that instance the debug log of the length of the array containing all hits is only 1 when it should be 2. Unless I am mistaken?

Thanks for your help!