@@ -11,6 +11,7 @@ var Resolver = {};
1111 Resolver . _restingThresh = 4 ;
1212 Resolver . _positionDampen = 0.9 ;
1313 Resolver . _positionWarming = 0.8 ;
14+ Resolver . _frictionNormalMultiplier = 5 ;
1415
1516 /**
1617 * Description
@@ -264,20 +265,25 @@ var Resolver = {};
264265
265266 // raw impulses
266267 var normalImpulse = ( 1 + pair . restitution ) * normalVelocity ,
267- normalForce = Common . clamp ( pair . separation + normalVelocity , 0 , 1 ) ;
268+ normalForce = Common . clamp ( pair . separation + normalVelocity , 0 , 1 ) * Resolver . _frictionNormalMultiplier ;
268269
269270 // coulomb friction
270- var tangentImpulse = tangentVelocity ;
271- if ( tangentSpeed > normalForce * pair . friction * timeScaleSquared )
272- tangentImpulse = normalForce * pair . friction * timeScaleSquared * tangentVelocityDirection ;
271+ var tangentImpulse = tangentVelocity ,
272+ maxFriction = Infinity ;
273+
274+ if ( tangentSpeed > pair . friction * pair . frictionStatic * normalForce * timeScaleSquared ) {
275+ tangentImpulse = pair . friction * tangentVelocityDirection * timeScaleSquared ;
276+ maxFriction = tangentSpeed ;
277+ }
273278
274279 // modify impulses accounting for mass, inertia and offset
275280 var oAcN = Vector . cross ( offsetA , normal ) ,
276281 oBcN = Vector . cross ( offsetB , normal ) ,
277- share = contactShare / ( pair . inverseMass + bodyA . inverseInertia * oAcN * oAcN + bodyB . inverseInertia * oBcN * oBcN ) ;
282+ share = contactShare / ( bodyA . inverseMass + bodyB . inverseMass + bodyA . inverseInertia * oAcN * oAcN + bodyB . inverseInertia * oBcN * oBcN ) ;
283+
278284 normalImpulse *= share ;
279- tangentImpulse *= share ;
280-
285+ tangentImpulse *= Math . min ( share , 1 ) ;
286+
281287 // handle high velocity and resting collisions separately
282288 if ( normalVelocity < 0 && normalVelocity * normalVelocity > Resolver . _restingThresh * timeScaleSquared ) {
283289 // high velocity so clear cached contact impulse
@@ -293,7 +299,7 @@ var Resolver = {};
293299
294300 // tangent impulse, tends to -maxFriction or maxFriction
295301 var contactTangentImpulse = contact . tangentImpulse ;
296- contact . tangentImpulse = Common . clamp ( contact . tangentImpulse + tangentImpulse , - tangentSpeed , tangentSpeed ) ;
302+ contact . tangentImpulse = Common . clamp ( contact . tangentImpulse + tangentImpulse , - maxFriction , maxFriction ) ;
297303 tangentImpulse = contact . tangentImpulse - contactTangentImpulse ;
298304 }
299305
0 commit comments