strange behavior in Box2D+LibGDX when applying impulse
Posted
by
Z0lenDer
on Game Development
See other posts from Game Development
or by Z0lenDer
Published on 2012-09-03T15:00:56Z
Indexed on
2012/09/03
15:52 UTC
Read the original article
Hit count: 315
I have been playing around with Box2D and LibGDX and have been using a sample code from DecisionTreeGames as the testing ground. Now I have a screen with four walls and a rectangle shape, lets call it a brick. When I use applyLinearImpulse to the brick, it starts bouncing right and left without any pattern and won't stop!
I tried adding friction and increasing the density, but the behavior still remains the same. Here are some of the code that might be useful:
method for applying the impulse:
center = brick.getWorldCenter();
brick.applyLinearImpulse(20, 0, center.x, center.y);
Defining the brick:
brick_bodyDef.type = BodyType.DynamicBody;
brick_bodyDef.position.set(pos); // brick is initially on the ground
brick_bodyDef.angle = 0;
brick_body = world.createBody(brick_bodyDef);
brick_body.setBullet(true);
brick_bodyShape.setAsBox(w,h);
brick_fixtureDef.density = 0.9f;
brick_fixtureDef.restitution = 1;
brick_fixtureDef.shape = brick_bodyShape;
brick_fixtureDef.friction=1;
brick_body.createFixture(fixtureDef);
Walls are defined the same only their bullet value is set to false
I would really appreciate it if you could help me have a change this code to have a realistic behavior (i.e. when I apply impulse to the brick it should trip a few times and then stop completely).
© Game Development or respective owner