Friction

Topics: Developer Forum
Feb 13, 2010 at 10:00 AM

Hello ,

I've been pulling my hair out because physics for some reason is so hard for me to grasp.

 I can't seam to under stand how to apply a tangent friction to the velocity of an object. I've looked at the arbiter class for hours but sadly I've had no luck because of how much is going on at once. I'm trying to start as simple as possible . 1 body and 1 static body .  Here is what I have done so far and you'll see where I've tried to make since of it all. Thanks for anyhelp. 

 

                                Vector2 normal = Vector2.Normalize(-r.MinimumTranslationVector);
                                CMPosition += r.MinimumTranslationVector;

                                Vector2 Position = SAT.GetCollisionPoint(fixtureA, fixtureB);


                                Vector2 CMToCornerPerp = Utility.GetPerpendicular(Position - CMPosition);

                                Vector2 Velocity = CMVelocity + AngularVelocity * CMToCornerPerp;

                                //_vn
                                float ImpulseNumerator = -( 1 + 0.6f) * Vector2.Dot(Velocity, normal);

                                float PerpDot = Vector2.Dot(CMToCornerPerp, normal);

                                float ImpulseDenominator = OneOverMass + OneOverCMMomentOfInertia * PerpDot * PerpDot;

                                float Impulse = ImpulseNumerator / ImpulseDenominator ;

                  
                                CMVelocity += (Impulse * OneOverMass * normal);// +(Impulse * OneOverMass * Discord.Collisions.Common.Math.Cross(normal, 1) * 0.2f);

                                AngularVelocity += Impulse * OneOverCMMomentOfInertia * PerpDot;


                                Vector2 tangent = Discord.Collisions.Common.Math.Cross(normal, 1);
                                float maxtangentImpulse = 0.2f * ImpulseNumerator;
                                float _vt = (CMToCornerPerp.X * tangent.X) + (CMToCornerPerp.Y * tangent.Y);
                                _tangentImpulse =  (-_vt);
                                _oldTangentImpulse = _tangentImpulse;
                                float tmpT = MathHelper.Clamp(_oldTangentImpulse + _tangentImpulse, -maxtangentImpulse,
                                                                           maxtangentImpulse);
                                _tangentImpulse = tmpT - _oldTangentImpulse;


                                CMVelocity.X += tangent.X * _tangentImpulse;
                                CMVelocity.Y += tangent.Y * _tangentImpulse;