基于在互联网上找到的box2d文档和教程(这里最好的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).
我是否会错过文档中的内容?有没有办法解决这个问题呢?
答案 0 :(得分:1)
好的,我想我找到了答案或者至少找到了解决方法。也许这对某人有帮助。
有问题的多边形夹具实际上是一个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.
答案 1 :(得分:0)
除了那两个之外,世界上还有其他装置吗?您是否正在检查以确保BeginContact事件真的适用于这两个灯具?有什么关于这个" 3-4次"会让你怀疑BeginContact可能用于其他灯具而不是静态传感器的行为?
我的猜测是,你的玩家正在移动一个由多个灯具制成的地面,你会看到玩家和地面灯具之间的BeginContact事件。