2014-09-05 110 views
0

基于Box2D的文档和教程在网上查到(最好的一个在这里http://www.iforce2d.net/b2dtut/collision-anatomy)我认为碰撞事件处理beginContact应该每次碰撞仅出现一次。Box2D的碰撞beginContant occurrs不止一次

但我的经验是,在某些情况下(我不能缩小这个下降到什么特别的事至今)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). 

我怀念在文档中的东西吗?有没有办法解决这个问题?

回答

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. 
0

是否有在世界上其他附着物,除了刚才那两个?您是否在检查以确保BeginContact事件真的适用于这两种灯具?有没有关于这种“3-4倍”的行为,会让你怀疑BeginContact可能适用于其他灯具,而不是静态传感器?我的猜测是,你的播放器正在从多个灯具组成的地面上移动,并且你看到了播放器和地面灯具之间的BeginContact事件。

+0

是的,这两个是唯一在场的灯具 - 他们是球员和奖金挂在空中。我发现,这个问题涉及到fixtureShape - 我用ChainShape得到鬼顶点advantge(顺便说一句感谢这些伟大的教程),这似乎可每每个链节beginContact。我已经将简单的PolygonShape夹具添加到玩家身上,并且需要使用斧子 - 每次碰撞开始接触呼叫。 – Lez77 2014-09-06 13:16:58