Unity2D - 忽略与边缘对撞机的碰撞

问题描述 投票:0回答:2

我试图让我的玩家忽略与我所拥有的平台上的边缘对撞机的碰撞。

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

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

unity3d collision-detection
2个回答
0
投票

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


0
投票

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

Physics2D settings

在底部,您可以看到可以相互碰撞的物理对象矩阵。只需取消选中哪一层不应与另一层发生碰撞。

Matrix

© www.soinside.com 2019 - 2024. All rights reserved.