Changes in Box2D 2.0.1

With the release of the 2.0.1 update of Box2D a couple of things have changed. Here are a couple of changes I have found. If you know of more post a comment.

Creating Bodies
Previously when creating bodies you had to specify if the body was static or dynamic, this is no longer the case. The engine itself will determine the body type based on its density setting. If you set the density of the shapes to 0 the body will be static and any non-zero value will make it dynamic. Example:

//Create a static body
var staticPoly:b2PolygonDef = new b2PolygonDef();
staticPoly.SetAsOrientedBox(10, 10, new b2Vec2(0, 0), 0);
staticPoly.friction = .5;
//Setting the density to 0 will make the body that contains this poly static
staticPoly.density = 0;
staticPoly.restitution=0;

var staticBodyDef:b2BodyDef = new b2BodyDef();
staticBodyDef.position.Set(0,0);
var staticBody = m_world.CreateBody(staticBodyDef);
//New shape instantiation does not need to define static or dynamic
staticBody.CreateShape(staticPoly)
staticBody.SetMassFromShapes();

//Create a dynamic body
var dynamicPoly:b2PolygonDef = new b2PolygonDef();
dynamicPoly.SetAsOrientedBox(10, 10, new b2Vec2(0, 0), 0);
dynamicPoly.friction = .5;
//Setting the density to any value greater then 0 will make the body that contains this poly dynamic
dynamicPoly.density = 1;
dynamicPoly.restitution=0;

var dynamicBodyDef:b2BodyDef = new b2BodyDef();
dynamicBodyDef.position.Set(0,0);
var dynamicBody = m_world.CreateBody(dynamicBodyDef);
//New shape instantiation does not need to define static or dynamic
dynamicBody.CreateShape(dynamicPoly)
dynamicBody.SetMassFromShapes();

Distance Joints
A couple of minor changes have been made to the distance joint type. It now includes a dampening factor and a frequency. I can’t really seem to figure out what they do though. I am probably wrong but I don’t think they are working properly in flash yet.

3 Responses to “Changes in Box2D 2.0.1”

  1. Clark Says:

    Thanks for this, i was looking on google to see what the frequencyHZ property did.

    I thought it was supposed to simulate a kind of soft joint which would be useful but no matter if i set it to 0.01 or 1000 it does not seem to make any difference to the running simulation.

    I think you must be right about it not working in Flash yet.

  2. ben Says:

    HI and thanks for everything inspiring on this blog !
    I didn’t took a look at this release but does the b2Body.IsStatic() still works ???

  3. Brettf Says:

    Not sure. Been a while since I have used it.