From de72b0ee9564e51f03fcc44b723ea9f708966ad3 Mon Sep 17 00:00:00 2001 From: jpagand Date: Mon, 2 Oct 2017 14:12:54 +0200 Subject: [PATCH] Apply force to bodies added before attractor --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e4c6249..5723768 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,10 @@ const MatterAttractors = { attractors = bodyA.plugin.attractors; if (attractors && attractors.length > 0) { - for (let j = i + 1; j < bodies.length; j += 1) { + for (let j = 0; j < bodies.length; j += 1) { + if (j === i) { + continue; + } let bodyB = bodies[j]; for (let k = 0; k < attractors.length; k += 1) { @@ -136,4 +139,4 @@ module.exports = MatterAttractors; * @param {Matter.Body} bodyA * @param {Matter.Body} bodyB * @returns {Vector|undefined} a force vector (optional) - */ \ No newline at end of file + */