File tree Expand file tree Collapse file tree
v3/src/physics/matter-js/lib/body Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments