Join box2d B2旋转点未断开
我想不出怎样才能使接头断裂。基本上,使用b2PolygonShape将旋转关节添加到两个b2Body上。但当汽车在上面行驶时,接头不会断裂。相反,汽车通过多边形形状 到目前为止,我一直在尝试下面的方法Join box2d B2旋转点未断开,join,cocos2d-iphone,box2d,break,Join,Cocos2d Iphone,Box2d,Break,我想不出怎样才能使接头断裂。基本上,使用b2PolygonShape将旋转关节添加到两个b2Body上。但当汽车在上面行驶时,接头不会断裂。相反,汽车通过多边形形状 到目前为止,我一直在尝试下面的方法 b2BodyDef bodyDef; bodyDef.position.Set(xPos/PTM_RATIO, yPos/PTM_RATIO); bodyDef.angle = atan(dy/dx); bodyDef.userData = sp;
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);
感谢您的帮助box2d中的接头不会断裂。如果您正在设置
enableLimit=true
则表示box2D将使用您的lowerAngle
和apperAngle
限制。box2d试验台中有一个易碎的示例。看一看。如果对关节施加的力过大,导致关节锚定位置分开,则可以检测它们何时移动过远,然后删除关节