Skip to content

Commit

Permalink
Merge pull request #1 from tylerfurtwangler/setPartsPositionFix
Browse files Browse the repository at this point in the history
fix: apply same delta from position to previous position when setParts runs
  • Loading branch information
tylerfurtwangler committed Dec 28, 2021
2 parents 014ef77 + 983d5ac commit 2a7fd84
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,14 @@ var Axes = require('../geometry/Axes');

// sum the properties of all compound parts of the parent body
var total = Body._totalProperties(body);
var positionDelta = Vector.sub(body.positionPrev, body.position);

body.area = total.area;
body.parent = body;
body.position.x = total.centre.x;
body.position.y = total.centre.y;
body.positionPrev.x = total.centre.x;
body.positionPrev.y = total.centre.y;
body.positionPrev.x = total.centre.x + positionDelta.x;
body.positionPrev.y = total.centre.y + positionDelta.y;

Body.setMass(body, total.mass);
Body.setInertia(body, total.inertia);
Expand Down

0 comments on commit 2a7fd84

Please sign in to comment.