Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

[LibGdx]Moving a fixture on a body

$
0
0

I’m working with Box2D and I have a basic platform and a box bounces off of it.

// Static Platform
    bdef.position.set(160 / PPM, 120 / PPM);
    bdef.type = BodyType.StaticBody;
    Body b = world.createBody(bdef);

    PolygonShape s = new PolygonShape();
    s.setAsBox(50 / PPM, 5 / PPM);
    fdef.shape = s;
    b.createFixture(fdef);



    // Falling Box
    bdef.position.set(160 / PPM, 200 / PPM);
    bdef.type = BodyType.DynamicBody;
    Body b2 = world.createBody(bdef);

    PolygonShape s2 = new PolygonShape();
    s2.setAsBox(5 / PPM, 5 / PPM);
    fdef.shape = s2;
    fdef.restitution = .75f;
    b2.createFixture(fdef);

Now I attempt to put both fixtures on the Body b.

// create platform
    bdef.position.set(160 / PPM, 120 / PPM);
    bdef.type = BodyType.StaticBody;
    Body b = world.createBody(bdef);

    PolygonShape s = new PolygonShape();
    s.setAsBox(50 / PPM, 5 / PPM);
    fdef.shape = s;
    b.createFixture(fdef);



    // create falling box
    bdef.position.set(160 / PPM, 200 / PPM);
    bdef.type = BodyType.DynamicBody;
    //Body b2 = world.createBody(bdef);

    PolygonShape s2 = new PolygonShape();
    s2.setAsBox(5 / PPM, 5 / PPM);
    fdef.shape = s2;
    fdef.restitution = .75f;
    b.createFixture(fdef);

Barely any change here. Now that they’re on the same body, I attempt to move one up a bit by changing the y value but nothing happens. How would I make the small box move from inside the larger one?

EDIT: I can make it a circle-shape and change the fixture position, but how would I with another box?


Viewing all articles
Browse latest Browse all 434

Trending Articles