diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js index 61de118d..07509c74 100644 --- a/src/constraint/Constraint.js +++ b/src/constraint/Constraint.js @@ -21,10 +21,8 @@ var Common = require('../core/Common'); (function() { - var _zeroVector = { x: 0, y: 0 }; - Constraint._warming = 0.4; - Constraint._torqueDampen = 0.8; + Constraint._torqueDampen = 1; Constraint._minLength = 0.000001; /** @@ -121,8 +119,8 @@ var Common = require('../core/Common'); fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic); if (!fixedA && !fixedB) { - Constraint.solve(constraints[i], timeScale); - } + Constraint.solve(constraints[i], timeScale); + } } }; diff --git a/src/core/Engine.js b/src/core/Engine.js index 42c9de10..2466fde5 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -149,7 +149,7 @@ var Body = require('../body/Body'); // update all body position and rotation by integration _bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds); - // update all constraints + // update all constraints (first pass) Constraint.preSolveAll(allBodies); for (i = 0; i < engine.constraintIterations; i++) { Constraint.solveAll(allConstraints, timing.timeScale); @@ -158,7 +158,6 @@ var Body = require('../body/Body'); // broadphase pass: find potential collision pairs if (broadphase.controller) { - // if world is dirty, we must flush the whole grid if (world.isModified) broadphase.controller.clear(broadphase); @@ -167,7 +166,6 @@ var Body = require('../body/Body'); broadphase.controller.update(broadphase, allBodies, engine, world.isModified); broadphasePairs = broadphase.pairsList; } else { - // if no broadphase set, we just pass all bodies broadphasePairs = allBodies; } @@ -201,6 +199,13 @@ var Body = require('../body/Body'); } Resolver.postSolvePosition(allBodies); + // update all constraints (second pass) + Constraint.preSolveAll(allBodies); + for (i = 0; i < engine.constraintIterations; i++) { + Constraint.solveAll(allConstraints, timing.timeScale); + } + Constraint.postSolveAll(allBodies); + // iteratively resolve velocity between collisions Resolver.preSolveVelocity(pairs.list); for (i = 0; i < engine.velocityIterations; i++) {