Big Stink wrote:
Hello,
Is it possible to change attributes like friction, restitution or density on the fly?
EDIT:: Just found this, seems to work fine

Code:
// Change property of body, in this case friction (there are other methods for other properties)
this.b2body.GetFixtureList().SetFriction(friction);
Hi,
the above doesn't work for me. I would like to change density after the creation of the bodies like this:
Code:
b2Def.fixture.friction = 0.5;
b2Def.fixture.restitution = 1.0;
b2Def.fixture.density = 0.2;
b2Def.fixture.shape = new b2CircleShape();
b2CircleShape(b2Def.fixture.shape).m_radius = 10 /Constants.RATIO;
b2Def.body.type = b2Body.b2_dynamicBody;
body11 = Constants._myWorld.CreateBody(b2Def.body);
body11.CreateFixture(b2Def.fixture);
b2Def.body.type = b2Body.b2_dynamicBody;
body22 = Constants._myWorld.CreateBody(b2Def.body);
body22.CreateFixture(b2Def.fixture);
body11.SetTransform(new V2(100 / Constants.RATIO, 0 / Constants.RATIO), 0);
body22.SetTransform(new V2(300 / Constants.RATIO, 0 / Constants.RATIO), 0);
body22.GetFixtureList().SetDensity(0.9); //<-- DOESN'T WORK
//body22.m_fixtureList.SetDensity(0.9); //<-- DOESN'T WORK EITHER
addEventListener(Event.ENTER_FRAME,goWorld);
body11.ApplyForce(new V2(0,5), body11.GetWorldCenter());
body22.ApplyForce(new V2(0,5), body22.GetWorldCenter());
The density keeps being the one defined on the creation of the bodies.
Anyone knows why or how to do it work??
Thanks you in advance and happy holidays.