基于box2d文档和在Internet中找到的教程(这里最好的一个是http://www.iforce2d.net/b2dtut/collision-anatomy),我假设碰撞事件处理程序beginContact每次碰撞只发生一次。
但我的经验是,在某些情况下(到目前为止,我无法将其缩小到特定的范围),beginContact被多次调用。
具体例子:
1st fixture is a box, belongs to static body and is a sensor
2nd fixture (which is also player body in 2d game I'm building)
is a polygon, belongs to dynamic body and is not a sensor.
Both are large enough so in debug mode it is absolutely clear
when these fixtures start to overlap and when they part.
Result is - while player body fixture passes through static sensor,
beginContact is called 3-4 times or more while fixtures keep oveplapping.
Velocity is moderate (fixtures keep overlapping for a whole second and more).我是不是错过了文档里的东西?有办法绕过这件事吗?
发布于 2014-09-05 12:40:57
好吧,我想我找到了答案,或者至少找到了解决办法。也许它会对某人有帮助。
问题中的多边形夹具实际上是一个ChainShape。在这种情况下,这条链的每一个环节似乎都开始了联系。切换到常规PolygonShape解决了这个问题。
我认为这是手册中描述这种情况的部分:
Contacts are objects created by Box2D to manage collision between two fixtures. If the fixture has children, such as a chain shape, then a contact exists for each relevant child. 发布于 2014-09-05 12:41:07
除了这两种外,世界上还有别的固定装置吗?您是否正在检查以确保BeginContact事件确实适用于这两个装置?这种"3-4次“行为是否会让您怀疑BeginContact可能用于其他固定装置,而不是静态传感器?
我的猜测是,你的玩家正在移动一个由多个固定装置组成的地面,你看到的是播放器和地面装置之间的BeginContact事件。
https://stackoverflow.com/questions/25677059
复制相似问题