body don't moove

Discuss issues specific the Java port of Box2D
Posts: 1
Joined: Sun Jul 26, 2009 2:37 pm

body don't moove

Postby kusoksna » Sun Jul 26, 2009 3:00 pm

I'm started to learn jbox2d, and now i'm stuck.
I created world, 2 bodies (static and dynamic). But dynamic body don't fall.

Code: Select all

  Vec2 v2min,v2max, v2gravity;
  AABB aabbWorld;
  World world;
  BodyDef bdGroundOne;
  Body bodyGroundOne, tankArmor,;
  //init world
    v2gravity = new Vec2(0.0f, -10.0f);
    aabbWorld = new AABB();
    aabbWorld.lowerBound = new Vec2(-1000.0f, -1000.0f);
    aabbWorld.upperBound = new Vec2(1000.0f, 1000.0f);
    world = new World(aabbWorld, v2gravity, false);
    //init ground
    bdGroundOne = new BodyDef();
    bdGroundOne.position = new Vec2(100.0f, 400.0f);
    bodyGroundOne = world.createBody(bdGroundOne);
    PolygonDef g1shapeDef = new PolygonDef();
    g1shapeDef.setAsBox(400, 20);
    BodyDef bdTank = new BodyDef();
    bdTank.position.set(300.0f, 200.0f);
    tankArmor = world.createBody(bdTank);
    PolygonDef pdTank = new PolygonDef();
    pdTank.setAsBox(50, 10);
    pdTank.density = 1.0f;
    pdTank.friction = 0.3f;
    pdTank.restitution = 0.1f;
    tankArmor.m_mass = 10.0f;

///// then every 1/60 second i call
world.step(1.0f/60.0f, 10);

But tankArmor Body don't fall. I also tried to apply force and velocity to body, but it not helped.

I know that i missed something, I hope you could point to my mistake.

PS: i'm using version 2.0.1 (august 2008), should I use version from SVN instead?

Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: body don't moove

Postby ewjordan » Sun Jul 26, 2009 4:33 pm

First, change bodyGroundOne.createShape(pdTank); to tankArmor.createShape(pdTank);

Then call tankArmor.setMassFromShapes() after all of that - without that call, the body will be considered static, as it has no mass.

Return to “Java”

Who is online

Users browsing this forum: No registered users and 1 guest