Collider2D碰撞检测异常-Rotating sprite does not rotate collider[Unity]

来源:互联网 发布:java编程规范第四版 编辑:程序博客网 时间:2024/06/09 17:32

问题描述:在Scene中明显看到碰撞体(绿框)有重叠,但是就是不触发碰撞事件。在移动物体时,发现当碰撞体未重叠的时候,反而会触发碰撞事件。经过排查,发现碰撞体所在的GameObject有设置水平反转(Y轴旋转180度)。

原因:对GameObjec的Y轴进行旋转之后,碰撞体还是保持未旋转之前的属性(虽然Scene中绿框显示有旋转,这里只是错觉)加上Anchor不在中心点,所以会导致物体和碰撞体位置不重合,才有了上面奇怪的现象。

解决方案:取消Y轴180度的旋转,将Scale设置为负,来达到反转的效果。

More:

Rotating 2D colliders in the X/Y axes is not supported. By this I mean that all 2D colliders ignore transform X/Y rotation and only use Z. This is especially important when you consider that we're limited in what deformation we can achieve via Box2D for some collider types such as the Circle collider. Allowing this kind of arbitrary transform would mean Box2D would need to support ellipse (even sheered ones) which it doesn't support.

This only parts of the transform component that are used are:

X/Y position (Z ignored)
Z rotation (X/Y ignored)
X/Y scale (Z ignored)

The colliders are not part of the SpriteRenderer component so whatever it does or doesn't use isn't tied into any of the colliders.

参考:

http://forum.unity3d.com/threads/rotating-sprite-does-not-rotate-collider.212327/


0 0
原创粉丝点击