diff --git a/src/collision/Distance.ts b/src/collision/Distance.ts index ffbf32a3..9f8a2349 100644 --- a/src/collision/Distance.ts +++ b/src/collision/Distance.ts @@ -112,7 +112,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i let saveCount = 0; let distanceSqr1 = Infinity; - let distanceSqr2 = Infinity; // Main iteration loop. let iter = 0; @@ -133,7 +132,7 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i // Compute closest point. const p = simplex.getClosestPoint(); - distanceSqr2 = p.lengthSquared(); + const distanceSqr2 = p.lengthSquared(); // Ensure progress if (distanceSqr2 >= distanceSqr1) { diff --git a/src/collision/shape/ChainShape.ts b/src/collision/shape/ChainShape.ts index 9b4c12a4..c2141a84 100644 --- a/src/collision/shape/ChainShape.ts +++ b/src/collision/shape/ChainShape.ts @@ -148,6 +148,10 @@ export class ChainShape extends Shape { _createLoop(vertices: Vec2Value[]): ChainShape { _ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0); _ASSERT && console.assert(vertices.length >= 3); + if (vertices.length < 3) { + return; + } + for (let i = 1; i < vertices.length; ++i) { const v1 = vertices[i - 1]; const v2 = vertices[i]; diff --git a/src/dynamics/Contact.ts b/src/dynamics/Contact.ts index a945ea43..c6c6a530 100644 --- a/src/dynamics/Contact.ts +++ b/src/dynamics/Contact.ts @@ -39,6 +39,7 @@ import { ContactImpulse, TimeStep } from "./Solver"; const _ASSERT = typeof ASSERT === 'undefined' ? false : ASSERT; +// Solver debugging is normally disabled because the block solver sometimes has to deal with a poorly conditioned effective mass matrix. const DEBUG_SOLVER = false; /** @@ -910,8 +911,7 @@ export class Contact { // 01/07 on Box2D_Lite). // Build the mini LCP for this contact patch // - // vn = A * x + b, vn >= 0, , vn >= 0, x >= 0 and vn_i * x_i = 0 with i = - // 1..2 + // vn = A * x + b, vn >= 0, x >= 0 and vn_i * x_i = 0 with i = 1..2 // // A = J * W * JT and J = ( -n, -r1 x n, n, r2 x n ) // b = vn0 - velocityBias