简体   繁体   English

使用Z轴的Box Collider 2D

[英]Box Collider 2D using Z axis

2D means that only X an Y axis matters but when i do OnTriggerStay2D(COllider2D col) and do Debug.Log(col.gameObject) it is fine as long as both objects stay at the same Z axis value (0, 0). 2D意味着仅X轴和Y轴很重要,但是当我执行OnTriggerStay2D(COllider2D col)Debug.Log(col.gameObject)时,只要两个对象都停留在相同的Z轴值(0,0)上就可以了。 When i move one of my objects to different value, they no longer collide. 当我将一个对象移动到不同的值时,它们不再发生碰撞。 Why is this happening and how to fix it? 为什么会发生这种情况以及如何解决?

在此处输入图片说明 在此处输入图片说明

Objects with different Z value will not collide, as Collider2D is also 2D which lies on XY plane and the Z is same as the objects Z. Z值不同的对象将不会发生碰撞,因为Collider2D也是2D,位于XY平面上,并且Z与对象Z相同。
So, if you change Z of a 2D object they wont collide. 因此,如果您更改2D对象的Z,它们将不会发生碰撞。 Hopefully the attached image clarifies. 希望附件中的图片可以澄清。
在此处输入图片说明
For different Z valued objects to collide, you'll need to use 3d colliders. 对于要碰撞的Z值不同的对象,您需要使用3d碰撞器。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM