Answer the question
In order to leave comments, you need to log in
How to change body mass in box2D?
I'm writing a Java game using libGDX which has the box2d physics engine built into it. Under certain circumstances, bodies must change their mass. How to correctly change the mass in box2D? I tried like this:
float newR = (float) Math.sqrt(newMass / Math.PI / this.body.getFixtureList().get(0).getDensity());// перерасчёт радиуса тела
MassData newMassData = new MassData();
newMassData.mass=newMass;
newMassData.center.set(newR, newR);
this.body.setMassData(newMassData);
this.body.resetMassData();
Answer the question
In order to leave comments, you need to log in
Try changing the density of the fixtures first, and then let Box2D recalculate the mass itself.
fixture->SetDensity( newDensity );
body->ResetMassData();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question