I am making a 2d color matching puzzle game with rigidbody2d and circlecollider2d. Everything works fine except that the collision does not always work.
I think the problem might be with how OverlapCircleAll is working. Here is my code for the ColorBubble class where i deal with the collision color matching in Update(), btw I tested it in FixedUpdate with not much difference
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position,.5f,mask,Mathf.NegativeInfinity,Mathf.Infinity);
foreach(Collider2D c2d in colliders)
{
if(c2d.gameObject.GetComponent<ColorBubble>() != null)
{
ColorBubble b = c2d.gameObject.GetComponent<ColorBubble>();
if(b.color == color)
{
matches.Add (b);
}
}
}
I heard that it might have something to do with the Z axis. In this post someone said the OverlapCircleAll ignores colliders with the same z axis. Is this really true? I know it has nothing to do with how i set up the color variable or the layermask because I checked those and they work. Most of the time the colors match correctly but sometimes they just do nothing when they hit.