0
votes

I have two objects...One static and one dynamic (it is a ball). Static object have polygon shape. Sommethimes when I hit the ball, ball passes through static object :(. I have played with density and other properties, but with no success. Do somebody knows how i can make static body to be impenetrable.

Here is my code

// Create ball body
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(110 / 2 / PTM_RATIO, 300 / PTM_RATIO);
ballBodyDef.userData = playerCartoonSprite;
ballBodyDef.bullet = YES;
playerCartoonBody = localWorld->CreateBody(&ballBodyDef);

// Create circle shape
b2CircleShape circle;
circle.m_radius = 10.0 / PTM_RATIO;

// Create shape definition and add to body
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 0.0f;
ballShapeDef.friction = 0.3f;
ballShapeDef.restitution = 1.f;
playerCartoonFixture = playerCartoonBody->CreateFixture(&ballShapeDef);

// static polygon object

    b2BodyDef bodyDef;
    bodyDef.type = b2_staticBody;

    int num = 6;
    b2Vec2 verts[] = {
        b2Vec2(8.6f / PTM_RATIO, 89.3f / PTM_RATIO),
        b2Vec2(5.0f / PTM_RATIO, 81.7f / PTM_RATIO),
        b2Vec2(10.5f / PTM_RATIO, 61.9f / PTM_RATIO),
        b2Vec2(13.1f / PTM_RATIO, 9.1f / PTM_RATIO),
        b2Vec2(17.3f / PTM_RATIO, 9.9f / PTM_RATIO),
        b2Vec2(12.7f / PTM_RATIO, 70.6f / PTM_RATIO)
    };

    b2PolygonShape boxShape;
    boxShape.Set(verts, num);
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &boxShape;
    bodyDef.position.Set(teeterSprite.position.x / PTM_RATIO, teeterSprite.position.y / PTM_RATIO);
    fixtureDef.shape = &boxShape;
    m_bodyA = world->CreateBody( &bodyDef );
    m_bodyA->CreateFixture( &fixtureDef );
1
Provide your code, please.Pavel

1 Answers