I'm trying to use Box2D in a game I'm making. I can't get my box to fall though, and I've checked the stuff in the other threads (mass isn't 0, and the body is inside the boundaries.)
Here is the relevant code.
Creating the world:
Adding a box:
Stepping the simulation, and some debug stuff I added:
Thanks to anyone that knows the answer.
Here is the relevant code.
Creating the world:
Code:
worldAABB.minVertex.set(0, 0);
worldAABB.maxVertex.set(width, height);
Vec2 gravity = new Vec2(0f, -10f);
pworld = new dynamics.World(worldAABB, gravity, true);
worldAABB.maxVertex.set(width, height);
Vec2 gravity = new Vec2(0f, -10f);
pworld = new dynamics.World(worldAABB, gravity, true);
Adding a box:
Code:
bd = new BodyDef();
sd = new BoxDef();
sd.density = 1;
sd.friction = 0.5f;
bd.addShape(sd);
//Some game-specific functions, but this part is definitely working
bd.position = getVec2DProperty("Position").toVec2();
sd.extents = getVec2DProperty("Size").toVec2();
sd = new BoxDef();
sd.density = 1;
sd.friction = 0.5f;
bd.addShape(sd);
//Some game-specific functions, but this part is definitely working
bd.position = getVec2DProperty("Position").toVec2();
sd.extents = getVec2DProperty("Size").toVec2();
Stepping the simulation, and some debug stuff I added:
Code:
public void doPhysics()
{
for (Body b = pworld.m_bodyList; b != null; b = b.m_next) {
System.out.println(b.m_position);
}
pworld.step(1/60, 10);
}
{
for (Body b = pworld.m_bodyList; b != null; b = b.m_next) {
System.out.println(b.m_position);
}
pworld.step(1/60, 10);
}
Thanks to anyone that knows the answer.