Unity2D-忽略与边缘碰撞器的碰撞

时间:2019-03-27 23:08:36

标签: unity3d collision-detection

我正在尝试让我的玩家忽略我在平台上与边缘碰撞器的碰撞。

这是我添加到播放器中的脚本

public class TestMovement : MonoBehaviour
{
public Rigidbody2D ball;
private GameObject purplePlat1;
private GameObject player;

// Start is called before the first frame update
void Start()
{
    purplePlat1 = GameObject.Find("purple_plat");
    player = GameObject.Find("circle-png-44659");

    ball = GetComponent<Rigidbody2D>();
    ball.AddForce(new Vector2(0, 10), ForceMode2D.Impulse);
    Debug.Log("start");
}

// Update is called once per frame
void Update()
{

}

void OnCollisionEnter2D(Collision2D collision)
{

    Physics2D.IgnoreCollision(purplePlat1.GetComponent<EdgeCollider2D> 
  (), GetComponent<CircleCollider2D>());
    Debug.Log("collision");

}
}

球仍在击中平台。我已经确认oncollisionenter方法正在触发。

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用Unity的layer系统来避免两者之间的collisions。为玩家设置一个图层,为边缘设置一个图层,并取消它们之间的碰撞。

答案 1 :(得分:0)

您可以做的是为不同类型的游戏对象创建一个图层蒙版。然后,打开您的Physics2D设置。

Physics2D settings

在底部,您可以看到一个物理对象矩阵,它们可以相互碰撞。只是取消选中哪一层不应该与另一层碰撞。

Matrix

相关问题