Skip to content

Commit cd62924

Browse files
committed
fix inertia change in Body.setMass
1 parent bccad67 commit cd62924

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • v3/src/physics/matter-js/lib/body

v3/src/physics/matter-js/lib/body/Body.js

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

294294
/**
295-
* Sets the mass of the body. Inverse mass and density are automatically updated to reflect the change.
295+
* Sets the mass of the body. Inverse mass, density and inertia are automatically updated to reflect the change.
296296
* @method setMass
297297
* @param {body} body
298298
* @param {number} mass
299299
*/
300300
Body.setMass = function(body, mass) {
301+
var moment = body.inertia / (body.mass / 6);
302+
body.inertia = moment * (mass / 6);
303+
body.inverseInertia = 1 / body.inertia;
304+
301305
body.mass = mass;
302306
body.inverseMass = 1 / body.mass;
303307
body.density = body.mass / body.area;
304308
};
305309

306310
/**
307-
* Sets the density of the body. Mass is automatically updated to reflect the change.
311+
* Sets the density of the body. Mass and inertia are automatically updated to reflect the change.
308312
* @method setDensity
309313
* @param {body} body
310314
* @param {number} density

0 commit comments

Comments
 (0)