diff --git a/sources/reactphysics3d/constraint/Contact.cpp b/sources/reactphysics3d/constraint/Contact.cpp index 903f47e7..3286984e 100644 --- a/sources/reactphysics3d/constraint/Contact.cpp +++ b/sources/reactphysics3d/constraint/Contact.cpp @@ -87,7 +87,10 @@ void Contact::evaluate() { upperBound = INFINITY_CONST; // Compute the error value of the constraint - errorValue = -PENETRATION_FACTOR * penetrationDepth; + Vector3D velocity1 = rigidBody1->getCurrentBodyState().getLinearVelocity(); + Vector3D velocity2 = rigidBody2->getCurrentBodyState().getLinearVelocity(); + double restitutionCoeff = rigidBody1->getRestitution() * rigidBody2->getRestitution(); + errorValue = restitutionCoeff * (normal.scalarProduct(velocity1) - normal.scalarProduct(velocity2)) + PENETRATION_FACTOR * penetrationDepth; // TODO : Add penetration // Compute the auxiliary jacobian matrix (this corresponds to the friction constraint) Vector3D r1CrossU1 = r1.crossProduct(frictionVectors[0]); diff --git a/sources/reactphysics3d/constraint/Contact.h b/sources/reactphysics3d/constraint/Contact.h index 1b4a1a96..6710027a 100644 --- a/sources/reactphysics3d/constraint/Contact.h +++ b/sources/reactphysics3d/constraint/Contact.h @@ -29,8 +29,8 @@ namespace reactphysics3d { // Constants -const double FRICTION_COEFFICIENT = 0.2; // Friction coefficient -const double PENETRATION_FACTOR = 0.1; // Penetration factor (between 0 and 1) which specify the importance of the +const double FRICTION_COEFFICIENT = 0.1; // Friction coefficient +const double PENETRATION_FACTOR = 0.6; // Penetration factor (between 0 and 1) which specify the importance of the // penetration depth in order to calculate the correct impulse for the contact /* -------------------------------------------------------------------