静态/动态体之间的 Box2D 碰撞导致断言
我第一次在 iPhone 上使用 BOX2D。总的来说,它非常好,但每当我创建一个同时包含静态和动态主体的场景时,我都会在 ContactManager 中的一行上反复收到断言。确切的行是...
b2Assert(bodyA->m_type == b2_dynamicBody || bodyB->m_type == b2_dynamicBody);
位于 void b2ContactManager::Collide() 中。这似乎表明当两个物体碰撞时它会断言,其中一个物体不是动态的......这根本没有意义。当然,动态物体应该与静态物体碰撞!
直到我奇怪地创建静态对象之前,它不会在这一行断言。我有大量的动态盒子在屏幕上移动。一旦我引入一个静态的,我就会在这里崩溃。
有人可以帮我吗?这似乎是“非常明显”类型的问题之一!
I'm using BOX2D for the first time on iPhone. On the whole it's been pretty good, but I keep repeatedly getting an assert on a line in ContactManager whenever I create a scene featuring both static and dynamic bodies. The exact line is...
b2Assert(bodyA->m_type == b2_dynamicBody || bodyB->m_type == b2_dynamicBody);
Which is in void b2ContactManager::Collide(). This seems to suggest that it's asserting when two objects collide, one of which isn't dynamic... which makes no sense at all. Of course dynamic bodies are supposed to collide with static ones!
It doesn't assert on this line until I create static objects strangely. I have tons of dynamic boxes moving arond the screen. As soon as I introduce one static one, I get a crash here.
Can anyone help me out? This seems like one of those 'Really obvious' type of problems!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建静态物体后,您会移动它们吗? (不仅仅是设置它们的初始位置?):我遇到了移动静态物体的问题,导致奇怪的问题(不是断言,而是奇怪的碰撞行为),然后发现 Box 区分静态和运动物体(分别为 b2_staticBody 和 b2_kinematicBody
)具有无限质量并且不会对力做出响应(按照静态),但据说它们可以手动移动(静态物体也可以手动移动,但预计它们在响应时不会被移动碰撞等,并可能导致奇怪的行为)
可能不是你的问题(因为你暗示它是在静态物体制作完成后立即发生的)但可能值得检查我想+如果你对 Box 比较陌生,你可能已经在手册。这对我来说只是新闻,因为我很久以前就开始使用 Box(突然出现了运动学的概念)
Do you move your static bodies after they're created? (Beyond just setting their initial position?): I had issues with static bodies being moved causing strange issues (not asserts, but odd collision behaviour) and then discovered that Box differentiates between static and kinematic bodies (b2_staticBody and b2_kinematicBody, respectively)
Kinematic bodies have infinite mass and don't respond to forces (as per static) but it is stated that they can manually be moved (static bodies can be moved manually too, but they're not expected to be moved whilst responding to collisions etc. and can cause weird behaviour)
Probably isn't your issue (since you imply it's immediately after static bodies are made) but might be worth checking I suppose + If you're relatively new to Box you may have already seen this in the manual. This only came as news to me because I started using Box ages ago (to suddenly have the concept of kinematic appear)
问题是两个非动态物体正在碰撞。这是不正确的,因为运动体和静态体不应相互碰撞。这种碰撞会被 box2d 忽略。但它正在发生在你的情况下。请提供一些 phys 初始化代码,以获得更详细的答案为什么会发生这种情况。
The problem is that two non-dynamic bodies are colliding. It's incorrect because kinematic and static bodies should not collide the each other. Such collision are ignored by box2d. But it is happening in your situation. Please provide some phys initialization code for more detailed answer why it's happening.