There is a problem, once you create a world body with a fixture:
var bd = new Box2D.b2BodyDef();
bd.set_position(new Box2D.b2Vec2(x, y))
//etc.
var body = world.CreateBody(bd);
var shape = new Box2D.b2PolygonShape();
shape.SetAsBox(width, height);
//etc.
var fixture = body.createFixture(shape, 0);
If you then change the shape:
shape.SetAsBox(new_width, new_height);
The shape remains the same place in memory, with the updated parameters -- however, the physics engine does not pick up the change -- things carry on as if it was the same (I find that strange).
I looked/tried the different functions for body, shape, and fixture to see if there was some way to kick in the physics engine to update it (i.e. SetAwake()) but none of those worked.
The solution I have right now is to store the fixture as variable, then destroy and replace it when needed:
function updateShape(){
body.DestroyFixture(fixture);
fixture = body.CreateFixture(new_shape, 0);
}
I had hoped there would be a more efficient way to change the shape, but there's a problem where the physics engine does not register the new shape.
There is a problem, once you create a world body with a fixture:
var bd = new Box2D.b2BodyDef();bd.set_position(new Box2D.b2Vec2(x, y))//etc.var body = world.CreateBody(bd);var shape = new Box2D.b2PolygonShape();shape.SetAsBox(width, height);//etc.var fixture = body.createFixture(shape, 0);If you then change the shape:
shape.SetAsBox(new_width, new_height);The shape remains the same place in memory, with the updated parameters -- however, the physics engine does not pick up the change -- things carry on as if it was the same (I find that strange).
I looked/tried the different functions for body, shape, and fixture to see if there was some way to kick in the physics engine to update it (i.e.
SetAwake()) but none of those worked.The solution I have right now is to store the fixture as variable, then destroy and replace it when needed:
function updateShape(){body.DestroyFixture(fixture);fixture = body.CreateFixture(new_shape, 0);}I had hoped there would be a more efficient way to change the shape, but there's a problem where the physics engine does not register the new shape.