From f7d18779be32a9fc8b22ea62c48092dd6d32b9a2 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 25 Nov 2017 14:11:53 +0000 Subject: [PATCH] fix inertia change in Body.setMass, closes #378 --- src/body/Body.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index 2048d87..59a4f3d 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -275,19 +275,23 @@ var Axes = require('../geometry/Axes'); }; /** - * Sets the mass of the body. Inverse mass and density are automatically updated to reflect the change. + * Sets the mass of the body. Inverse mass, density and inertia are automatically updated to reflect the change. * @method setMass * @param {body} body * @param {number} mass */ Body.setMass = function(body, mass) { + var moment = body.inertia / (body.mass / 6); + body.inertia = moment * (mass / 6); + body.inverseInertia = 1 / body.inertia; + body.mass = mass; body.inverseMass = 1 / body.mass; body.density = body.mass / body.area; }; /** - * Sets the density of the body. Mass is automatically updated to reflect the change. + * Sets the density of the body. Mass and inertia are automatically updated to reflect the change. * @method setDensity * @param {body} body * @param {number} density