IsTouching and OverlapCollider contradicting each other?

711 Views Asked by At

From a top down perspective I am trying to make it so that a player can fall into a pit. I want to use 2DCircleCollider.IsTouching(ContactFilter2D) to check whether the players hitbox overlaps with the ground but this always returns false despite OverlapCollider fuctioning correctly with the same contactfilter. My character has a rigidbody attatched and the ground does not. Are these two functions fundamentally different or am I using IsTouching wrong?

EDIT

public class CollisionChecker : MonoBehaviour
{
    private CircleCollider2D p1Box;
    private Rigidbody2D rb2d;
    //public LayerMask Iceberg;
    public ContactFilter2D cf2d;
    // Use this for initialization
    void Start()
    {
        p1Box = GetComponent<CircleCollider2D>();
        rb2d = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        int debugcount = 0;

        Collider2D\[\] results = new Collider2D\[100\];
        p1Box.OverlapCollider(cf2d, results);
        for (int i = 0; i < results.Length; i++)
        {
            if (results\[i\] != null)
            {
                debugcount++;
            }
            else
            {
                break;
            }
        }
        Debug.Log(debugcount);
        Debug.Log(p1Box.IsTouching(cf2d));
        debugcount = 0;
        //if (!rb2d.IsTouchingLayers(Iceberg))
        //{
        //    Debug.Log("AAAAAAAAAAAAAAA");
        //}
    }
}

player object with inspector

ground tile with inspector

0

There are 0 best solutions below