Fixed infinite positional error bias

This commit is contained in:
Diren D Bharwani 2023-03-02 07:08:45 +08:00
parent f4b7618fc2
commit 199a9aa025
1 changed files with 5 additions and 3 deletions

View File

@ -214,7 +214,9 @@ namespace SHADE
* restituion bias = restitution * (relative velocity /dot normal)
*/
const float ERROR_BIAS = -SHPHYSICS_BAUMGARTE * INV_DT * std::max(0.0f, contact.penetration - SHPHYSICS_LINEAR_SLOP);
float errorBias = 0.0f;
if (std::fabs(contact.penetration) > SHPHYSICS_LINEAR_SLOP)
errorBias = -SHPHYSICS_BAUMGARTE * INV_DT * std::max(0.0f, contact.penetration - SHPHYSICS_LINEAR_SLOP);
// Warm starting
// Compute impulses
@ -235,7 +237,7 @@ namespace SHADE
const float RESTITUTION_BIAS = std::fabs(RV_N) > SHPHYSICS_RESTITUTION_THRESHOLD ? -constraint.restitution * RV_N : 0.0f;
contact.bias = ERROR_BIAS + RESTITUTION_BIAS;
contact.bias = errorBias + RESTITUTION_BIAS;
}
velocityStateA.LinearVelocity = vA;
@ -247,7 +249,7 @@ namespace SHADE
void SHContactSolver::solve() noexcept
{
static const float TEMP_INF = std::numeric_limits<float>::infinity();
for (auto& [key, constraint] : contactConstraints)
{