简体   繁体   English

如何使 2D 对撞机仅与特定游戏对象发生碰撞而不使用图层?

[英]How to make a 2D collider collide only with a specific GameObject without using layers?

Suppose I have a BoxCollider2D in my player GameObject and I want it to ignore all other colliders, except another BoxCollider2D within an item.假设我的玩家游戏对象中有一个 BoxCollider2D,我希望它忽略所有其他碰撞器,项目中的另一个 BoxCollider2D 除外。

All of them are in the same layer and the layer collides with itself.它们都在同一层中,并且该层与自身发生碰撞。

I know that there is the Physics2D.IgnoreCollision method, but is there a way to ignore ALL collisions except the collider of this item GameObject, that is in the same layer than the players?我知道有Physics2D.IgnoreCollision方法,但是有没有办法忽略除此项目 GameObject 的对撞机之外的所有碰撞,即与玩家在同一层?

In a 2D game you can use the depth to avoid collision if you don't want to use layers.在 2D 游戏中,如果您不想使用图层,可以使用深度来避免碰撞。 For example, you can have all the objects that are part of the collision at z=0 and all that needs to avoid collision will be at z=1.例如,您可以在 z=0 处拥有属于碰撞一部分的所有对象,而所有需要避免碰撞的对象都位于 z=1 处。 Since its a 2D game there won't be any difference in what the camera renders.由于它是 2D 游戏,因此相机渲染的内容不会有任何差异。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有什么办法可以让对撞机只与特定的游戏对象发生碰撞而不使用图层? - Is there any way to make a collider collide only with a specific GameObject without using layers? 使用 OnCollisionEnter2D() Unity 2D 时仅使用我的游戏对象的 1 个对撞机 - Only use 1 collider of my gameobject when using OnCollisionEnter2D() Unity 2D 我怎样才能让 unity 3d 中的对撞机不与我的播放器发生碰撞,但仍然与光线投射发生碰撞? (团结新手!) - How could I make a collider in unity 3d not collide with my player, but still collide with raycasts? (new to unity!) 有没有办法让 2D Collider 忽略另一个 2D Collider? - Is there a way to make a 2D Collider Ignore another 2D Collider? 如何在不重叠的情况下使用 animation 调整 2d 对撞机的大小 - How to resize collider 2d with animation without overlapping Unity 2D以特定角度启动gameObject而不影响速度 - Unity 2D launch gameObject at a specific angle without affecting speed 即使我创建 2D 碰撞盒,我的 2D 游戏中的角色也不会发生碰撞 - My characters in my 2D game do not collide even when i create 2D collider box 如何销毁所有与Unity3D中的特定2D对象碰撞的2D对象? - How to destroy all 2D objects that collide with a specific 2D one in Unity3D? (2D) 在 Unity 中使用脚本制作 GameObject Shake - (2D) Make a GameObject Shake using script in Unity 使用Z轴的Box Collider 2D - Box Collider 2D using Z axis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM