box2d b2RevoluteJoint不破

时间:2011-03-23 23:49:30

标签: join cocos2d-iphone box2d break

我无法弄清楚如何使关节易碎。基本上,一个旋转关节被添加到两个b2Body与b2PolygonShape。但是当汽车在它上面移动时,关节不会破裂。而是汽车穿过多边形形状。

到目前为止,没有运气试过以下

            b2BodyDef bodyDef;
    bodyDef.position.Set(xPos/PTM_RATIO, yPos/PTM_RATIO);
    bodyDef.angle = atan(dy/dx);

    bodyDef.userData = sp;
    bodyDef.type = b2_dynamicBody;

    b2Body* body = world->CreateBody(&bodyDef);

    b2PolygonShape shape;
    b2Vec2 rectangle1_vertices[4];
    rectangle1_vertices[0].Set(-len/2, -width/2);
    rectangle1_vertices[1].Set(len/2, -width/2);
    rectangle1_vertices[2].Set(len/2, width/2);
    rectangle1_vertices[3].Set(-len/2, width/2);
    shape.Set(rectangle1_vertices, 4);

    b2FixtureDef fd;
    fd.shape = &shape;
    fd.density = 10.0f;
    body->CreateFixture(&fd);

    edge.body = body;

// The code below is not breaking the joint even though enableLimit = true. 
                b2RevoluteJointDef jointDef;
            b2Vec2 anchor = vertex.body->GetPosition();
            jointDef.lowerAngle = -10.0 * b2_pi / 180.0f;
            jointDef.upperAngle = 10.0 * b2_pi / 180.0f;
            jointDef.enableLimit = true;
            jointDef.maxMotorTorque = 1000.0f;
            jointDef.enableMotor = true;

            //prevEdge and edge are b2Body with b2PolygonShape.
            jointDef.Initialize(prevEdge.body, edge.body, anchor);
            world->CreateJoint(&jointDef);

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

box2d中的关节不可破坏。如果您是设置enableLimit = true,则表示box2D将使用您的lowerAngleapperAngle限制。 box2d testbed中有一个可破解的例子。看一看。

答案 1 :(得分:0)

如果你对关节施加如此大的力以使关节锚位置移开,你可以检测到它们移动得太远而只是删除关节。