问题描述
我是 box2d 的新手.我在 box2d 中开始了一个新游戏,并在世界上创建了 5 个动态物体.最初我需要防止它们之间发生碰撞.所以我将所有身体的组索引设置为负数.触摸身体后,我想允许与该身体发生碰撞.如何重置组索引.请帮忙..
I am new to box2d. I have started a new game in box2d and created 5 dynamic bodies in the world. Initially I need to prevent collision between them. so i set group index of all bodies negative. After touching a body i want to allow the collision with that body. How to reset the group index. Please help..
推荐答案
听起来您正在寻找类似的东西
Sounds like you're looking for something like
b2Body *body = world->GetBodyList();
b2Filter filter = body->GetFilterData();
filter.maskBits = filter.maskBits | THE_RELEVANT_CATEGORY_BITS;
body->SetFilterData(&filter);
这里的想法是您可以获取任何对象的碰撞过滤数据,使用一些布尔逻辑将碰撞数据分配给 maskBits 字段,然后使用 SetFilterData 将新的碰撞数据应用于主体.THE_RELEVANT_CATEGORY_BITS 应该是枚举类型的元素,其中每个冲突过滤类别都由一个唯一的二进制整数表示.
The idea here is that you can get the collision filtering data for any object, use some boolean logic to assign collision data to the maskBits field, and then use SetFilterData to apply that new collision data to the body. THE_RELEVANT_CATEGORY_BITS should be an element of an enumerated type in which each collision filtering category is represented by a unique binary integer.
查看 box2D 教程以了解有关此 http://www.iforce2d.net/b2dtut 的更多信息/碰撞过滤
Check out the box2D tutorial for more on this http://www.iforce2d.net/b2dtut/collision-filtering
这篇关于如何在box2d中动态更改主体的组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!