Reputation: 1093
I am new to box2d and libgdx game development framework.
I have created a world and a circle shape.
I am in Trouble with Gravity. The Circle I created in libgdx box2d is not falling under gravity. plz help me i stuck at this problem .
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
box2dDebugRenderer.render(world, orthographicCamera.projection);
world.step(TIME_STEMP, VELOCITY_ITERAIONS, POSITION_ITERATION);
System.out.println(b.getPosition().y);
}
@Override
public void resize(int width, int height) {
orthographicCamera.setToOrtho(false, width/10, height/10);
orthographicCamera.update();
}
@Override
public void show() {
world = new World(new Vector2(0, -9.81f), true);
box2dDebugRenderer = new Box2DDebugRenderer();
orthographicCamera = new OrthographicCamera();
BodyDef balldef = new BodyDef();
balldef.type = BodyType.DynamicBody;
balldef.position.set(0, 1);
CircleShape ballshape = new CircleShape();
ballshape.setRadius(1f);
FixtureDef ballfixture = new FixtureDef();
ballfixture.density = 1000f;
ballfixture.friction = .3f;
ballfixture.restitution = .7f;
ballfixture.shape = ballshape;
b = world.createBody(balldef);
f = b.createFixture(ballfixture);
}
Upvotes: 2
Views: 554
Reputation: 16526
This is your problem.-
final float TIME_STEMP = 1/60;
You're doing an integer division resulting in 0
. In other words, your world is stuck in time. Try this one.-
final float TIME_STEMP = 1.0f / 60.0f;
Upvotes: 6