最近在使用box2d最一些物理模拟,遇到了一些问题,希望能够的到解答。
如下代码创建了一个边角为圆弧的刚体,在它的底部和两侧分别都有一个碰撞检测器,正常情况下运行良好,一旦和我创建的其他刚体的边角发生碰撞之后,这些检测器就有可能失去作用。
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.userData = (void*)100000;
bodyDef.linearDamping = 0.0f;
bodyDef.position.Set(this->sprite->getPosition().x / PTM_RATIO, this->sprite->getPosition().y / PTM_RATIO);
animalBody = MapLayer::GetMWorld()->CreateBody(&bodyDef); //加入mWorld
b2FixtureDef bodyFixture;
bodyFixture.density = 1.0f;
bodyFixture.friction = 0.0f;
bodyFixture.restitution = 0.0f;
b2CircleShape circleShape;
circleShape.m_radius = 5.0f/PTM_RATIO;
circleShape.m_p.Set(25.0f/PTM_RATIO, 25.0f/PTM_RATIO);
bodyFixture.shape = &circleShape;
animalBody->CreateFixture(&bodyFixture);
circleShape.m_p.Set(25.0f/PTM_RATIO, -25.0f/PTM_RATIO);
bodyFixture.shape = &circleShape;
animalBody->CreateFixture(&bodyFixture);
circleShape.m_p.Set(-25.0f/PTM_RATIO, 25.0f/PTM_RATIO);
bodyFixture.shape = &circleShape;
animalBody->CreateFixture(&bodyFixture);
circleShape.m_p.Set(-25.0f/PTM_RATIO, -25.0f/PTM_RATIO);
bodyFixture.shape = &circleShape;
animalBody->CreateFixture(&bodyFixture);
b2PolygonShape midleShape;
midleShape.SetAsBox(25.0f/PTM_RATIO,30.0f/PTM_RATIO);
bodyFixture.shape = &midleShape; //形状
animalBody->CreateFixture(&bodyFixture);
midleShape.SetAsBox(25.0f/PTM_RATIO,2.5f/PTM_RATIO, b2Vec2(0.0f,-27.5f/PTM_RATIO), 0.0f);
bodyFixture.shape = &midleShape; //形状
bodyFixture.userData = (void*)3;
animalBody->CreateFixture(&bodyFixture);
midleShape.SetAsBox(2.5f/PTM_RATIO,25.0f/PTM_RATIO, b2Vec2(-27.5f/PTM_RATIO,0.0f), 0.0f);
bodyFixture.shape = &midleShape; //形状
bodyFixture.userData = (void*)4;
animalBody->CreateFixture(&bodyFixture);
midleShape.SetAsBox(2.5f/PTM_RATIO,25.0f/PTM_RATIO, b2Vec2(27.5f/PTM_RATIO,0.0f), 0.0f);
bodyFixture.shape = &midleShape; //形状
bodyFixture.userData = (void*)5;
animalBody->CreateFixture(&bodyFixture);
