首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Box2d冲突beginContant不止一次发生

Box2d冲突beginContant不止一次发生
EN

Stack Overflow用户
提问于 2014-09-05 00:43:47
回答 2查看 277关注 0票数 0

基于box2d文档和在Internet中找到的教程(这里最好的一个是http://www.iforce2d.net/b2dtut/collision-anatomy),我假设碰撞事件处理程序beginContact每次碰撞只发生一次。

但我的经验是,在某些情况下(到目前为止,我无法将其缩小到特定的范围),beginContact被多次调用。

具体例子:

代码语言:javascript
复制
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).

我是不是错过了文档里的东西?有办法绕过这件事吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-05 12:40:57

好吧,我想我找到了答案,或者至少找到了解决办法。也许它会对某人有帮助。

问题中的多边形夹具实际上是一个ChainShape。在这种情况下,这条链的每一个环节似乎都开始了联系。切换到常规PolygonShape解决了这个问题。

我认为这是手册中描述这种情况的部分:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2014-09-05 12:41:07

除了这两种外,世界上还有别的固定装置吗?您是否正在检查以确保BeginContact事件确实适用于这两个装置?这种"3-4次“行为是否会让您怀疑BeginContact可能用于其他固定装置,而不是静态传感器?

我的猜测是,你的玩家正在移动一个由多个固定装置组成的地面,你看到的是播放器和地面装置之间的BeginContact事件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25677059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档