Skip to content

Commit f7d1877

Browse files
committed
fix inertia change in Body.setMass, closes #378
1 parent 894c1ef commit f7d1877

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/body/Body.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,23 @@ var Axes = require('../geometry/Axes');
275275
};
276276

277277
/**
278-
* Sets the mass of the body. Inverse mass and density are automatically updated to reflect the change.
278+
* Sets the mass of the body. Inverse mass, density and inertia are automatically updated to reflect the change.
279279
* @method setMass
280280
* @param {body} body
281281
* @param {number} mass
282282
*/
283283
Body.setMass = function(body, mass) {
284+
var moment = body.inertia / (body.mass / 6);
285+
body.inertia = moment * (mass / 6);
286+
body.inverseInertia = 1 / body.inertia;
287+
284288
body.mass = mass;
285289
body.inverseMass = 1 / body.mass;
286290
body.density = body.mass / body.area;
287291
};
288292

289293
/**
290-
* Sets the density of the body. Mass is automatically updated to reflect the change.
294+
* Sets the density of the body. Mass and inertia are automatically updated to reflect the change.
291295
* @method setDensity
292296
* @param {body} body
293297
* @param {number} density

0 commit comments

Comments
 (0)