从自上而下的角度来看,我试图让玩家可以掉进坑里。我想使用 2DCircleCollider.IsTouching(ContactFilter2D) 来检查玩家的碰撞箱是否与地面重叠,但这总是返回 false,尽管 OverlapCollider 使用相同的接触过滤器正常工作。我的角色连接了刚体,而地面没有。这两个功能是根本不同还是我使用 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");
//}
}
}