A breakable wall in box2d

207 views Asked by At

Using box2d and cocos2d, i need to create some b2body model , where the that body will be a line or a whole ( made of vectors with coding) that can be "pass-able" by a ball , when the ball is hitting him in high velocity .

So ,in other words ,like in the real world, the material should be soft, that can be broken.

A zero density does not do that . Is there another way for this ?

Thanks .

1

There are 1 answers

0
Umesh Sharma On

why make One????? make the wall using bricks(Smaller particles) that will fall incase with collision.....

The other way to get this functionality is using presolve of the contactListener.... there check the collision between two bodies and if speed of one is grater than a certain value set contact disabled...

Take this code from one of my games.....

`enter code here`if ((userDataObjectA.userDataType == kObjectTypeMotherShip || userDataObjectB.userDataType == kObjectTypeMotherShip) && (userDataObjectA.userDataType == kObjectTypeSaucer || userDataObjectB.userDataType == kObjectTypeSaucer)) {
        b2WorldManifold worldManifold;
        contact->GetWorldManifold(&worldManifold);
        if (userDataObjectA.userDataType == kObjectTypeSaucer) {
            b2Vec2 saucerVelocity = bodyA->GetLinearVelocity();
            if (saucerVelocity.y > 2) {
                contact->SetEnabled(false);
            }
        } else if (userDataObjectB.userDataType == kObjectTypeSaucer) {
            b2Vec2 saucerVelocity = bodyB->GetLinearVelocity();
            if (saucerVelocity.y > 2) {
                contact->SetEnabled(false);
            }
        }
  }