diff --git a/src/collision/Resolver.js b/src/collision/Resolver.js index 84edce9..7ea51ad 100644 --- a/src/collision/Resolver.js +++ b/src/collision/Resolver.js @@ -49,9 +49,10 @@ var Bounds = require('../geometry/Bounds'); * Find a solution for pair positions. * @method solvePosition * @param {pair[]} pairs + * @param {number} delta * @param {number} positionIterations */ - Resolver.solvePosition = function(pairs, positionIterations) { + Resolver.solvePosition = function(pairs, delta, positionIterations) { var i, pair, collision, @@ -61,6 +62,7 @@ var Bounds = require('../geometry/Bounds'); contactShare, positionImpulse, positionDampen = Resolver._positionDampen * Common.clamp(20 / positionIterations, 0, 1), + slopDampen = delta / Common._timeUnit, pairsLength = pairs.length; // find impulses required to resolve penetration @@ -91,7 +93,7 @@ var Bounds = require('../geometry/Bounds'); bodyA = collision.parentA; bodyB = collision.parentB; normal = collision.normal; - positionImpulse = pair.separation - pair.slop; + positionImpulse = pair.separation - pair.slop * slopDampen; if (bodyA.isStatic || bodyB.isStatic) positionImpulse *= 2; diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js index ea3de49..eda3ee4 100644 --- a/src/constraint/Constraint.js +++ b/src/constraint/Constraint.js @@ -186,8 +186,9 @@ var Common = require('../core/Common'); // solve distance constraint with Gauss-Siedel method var difference = (currentLength - constraint.length) / currentLength, isRigid = constraint.stiffness >= 1 || constraint.length === 0, - stiffness = isRigid ? constraint.stiffness : constraint.stiffness * timeScale * timeScale, - damping = constraint.damping * timeScale, + stiffness = isRigid ? constraint.stiffness * timeScale + : constraint.stiffness * timeScale * timeScale, + damping = constraint.damping * timeScale * timeScale, force = Vector.mult(delta, difference * stiffness), massTotal = (bodyA ? bodyA.inverseMass : 0) + (bodyB ? bodyB.inverseMass : 0), inertiaTotal = (bodyA ? bodyA.inverseInertia : 0) + (bodyB ? bodyB.inverseInertia : 0), diff --git a/src/core/Engine.js b/src/core/Engine.js index 788fe54..3c1c716 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -149,7 +149,7 @@ var Body = require('../body/Body'); // iteratively resolve position between collisions Resolver.preSolvePosition(pairs.list); for (i = 0; i < engine.positionIterations; i++) { - Resolver.solvePosition(pairs.list, engine.positionIterations); + Resolver.solvePosition(pairs.list, delta, engine.positionIterations); } Resolver.postSolvePosition(allBodies);