Unity2D-忽略与边缘碰撞器的碰撞 [英] Unity2D - Ignore collision with edge collider
问题描述
我正在尝试让我的玩家忽略与我所拥有平台上的边缘对撞机的碰撞.
I am trying to have my player ignore the collision with an edge collider on a platform i have.
这是我添加到播放器中的脚本
Here's the script that I have added to the player
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方法正在触发.
The ball is still hitting the platform. I have confirmed that the oncollisionenter method is firing.
推荐答案
您可以做的是为不同类型的游戏对象创建一个图层蒙版.然后,打开您的Physics2D设置.
What you can do is create a layer mask for the different type of game objects. Then, open your Physics2D settings.
在底部,您可以看到一个物理对象矩阵,它们可以相互碰撞.只需取消选中哪一层不应与另一层碰撞即可.
On the bottom part, you can see a matrix of physics objects that can collide to one another. Just uncheck which layer should not collide with the other.
这篇关于Unity2D-忽略与边缘碰撞器的碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!