Search code examples
box2dcocos2d-x

b2Edgeshape is not detecting in groundbox


I want to create line box2d at runtime(touch event)

I have created the above. But i have issue on that. The issue is line shape(b2EdgeShape) is not detected or collision in groundbox which is also b2EdgeShape.

Here is the coding:

Init Function:

       b2EdgeShape groundBox;

        // bottom

        groundBox.Set(b2Vec2(0,0), b2Vec2((s.width)/PTM_RATIO,0));
        groundBody->CreateFixture(&groundBox,0);

CCTouch Event:

        b2EdgeShape shape1;
        b2FixtureDef fdf;
        fdf.density = 1.0;
        fdf.friction = 0.3;
        fdf.restitution = 0.2;
        fdf.shape=&shape1;
        shape1.Set(b2Vec2(s.x, s.y), b2Vec2(e.x, e.y));
        body->CreateFixture(&shape1,0.0f);

Is any wrong or logic issues?


Solution

  • Two edge shapes cannot collide with each other.
    

    According to Box2d manual.......

    A major limitation of edge shapes is that they can collide with circles and polygons but
    not with themselves. The collision algorithms used by Box2D require that at least one of two colliding
    shapes have volume. Edge shapes have no volume, so edge-edge collision is not possible.