Touching和OverlapCollider是否相互矛盾?

时间:2018-08-08 13:15:47

标签: unity3d top-down

从上至下的角度来看,我试图做到这一点,以便玩家可以进入维修区。我想使用2DCircleCollider.IsTouching(ContactFilter2D)检查玩家的击打箱是否与地面重叠,但是即使OverlapCollider与相同的contactfilter正确配合,它也始终返回false。我的角色有刚体,地面没有。这两个功能有根本区别吗?还是我使用IsTouching错误?

编辑

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 个答案:

没有答案