Unity3D的碰撞检测遇到的有趣BUG

Assume that A and B are both given the Box Collider. If we use the function bound.Intersect() to detect the collide between A and B, there seems a way to make this kind of detection effectiveness and the method is:

1. Rotate A and B

2. use the function bound.Intersect() to detect the collision event.

 

then we can see we fail to detect this collision event.

If we skip the first step, we can dectect the collision well.

 

假如A与B已经被赋值好了一个Box Collider用于检测碰撞,碰撞检测函数用的是Bound.Intersect(),有一种方法似乎可以让这个函数失效

1. 旋转A与B

2. 利用Bound.Intersect()检测碰撞

我们可以看到AB的碰撞无法检测,而跳过第一个步骤就可以正常检测。

 

不知道是什么原因导致的……

 

Finally, the bug is debugged. It is just because whether you have understand the word 'intersect' or not. 'Iintersect' mean A's origion  is in B or B' origion is in A, then the U3D wont think A and B is collide under the function bound.Intersect() if the origions of both A and B are not in the other box collider.

最终,我终于通过Intersect这个词汇的本意得知了BUG的缘由,Intersect函数并不是检测包围盒是否有交集,而是检测A或者B物体的原点是不是在另一个物体的包围盒中,虽然感觉很不合理,但是实验结果是这样的,我觉得这也是U3D引擎的BUG吧,所以 当我旋转 A  和 B物体的时候,他们的原点脱离了另一个物体的包围盒,虽然看起来他们的包围盒还是有交集,但是由于原点不在另一方的包围盒中,碰撞检测的返回值仍然是false 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章