- // Velocity projection is greater than closest distance
- if (projVel > closestDistance) {
- var time = closestDistance / projVel;
- // Correct velocity by time factor
- var correctedVelocity = velocity.sub(velocity.mulScalar(1.0 - time));
- // Get corrected position
- var correctionPosition = prevPos.add(correctedVelocity);
- // Set new position to corrected one
- particle.position.setup(correctionPosition);
- // Calculate new velocity
- var restitution = 0;
- var Vn = normal.mulScalar(normal.dot(velocity));
- var Vt = velocity.sub(Vn);
- var Vi = Vt.sub(Vn.mulScalar(restitution));
- particle.velocity.setup(Vi);
- /*
- // Set new position to corrected one
- VecMath.Vec2Add(correctionPosition, normal.mulScalar(Constants.Epsilon), particle.position);
- // add a velocity impulse against the collision normal
- VecMath.Vec2Add(particle.velocity, normal.mulScalar(projVel), particle.velocity);
- */
- // Reset force
- this.forces[index].zero();
- particle.force.zero();
- }