Position correction and Impulse Resolution Issue:
Hello all. I am having some issues with my impulse resolution. So far I have an intersection test which returns whenever two AABB objects have collided. This works perfectly.
Next, when the two objects have intersected, I need to do impulse resolution and then position correction to move the dynamic object in a certain manor. So far I have it working perfectly on the two sides:
The arrows indicate that the response works fine on these axis's.
// ---- Calculating normals in x and y float a, b, otherA, otherB; a = max.y - min.y; b = min.x - max.x; otherA = other.max.y - other.min.y; otherB = other.min.x - other.max.x; float magnitude = sqrt(a*a) + (b* b); float magnitudeOther = sqrt(otherA * otherA) + (otherB * otherB); vector2D normal=(a/magnitude,b/magnitude); vector2D normalOther(otherA / magnitudeOther, otherB / magnitudeOther);
The first thing I do is calculate my normals which I use later on for my correction.
// ---- Masses so I can use inverse mass - hard coded for now float m, mOther, inverse, inverseOther; m = 50; mOther = 50; inverse = 1.f/m; inverseOther = 1.f/mOther;The next thing I do is calculate my extents:
vector2D extent, otherExtent; extent = min.add(max).scale(0.5f); otherExtent = other.min.add(other.max).scale(0.5f); float e = 0.6; float slop = 0.01; float percentage = 0.1;From here I now work out my impulse resolution and position correction:
vector2D correction, pd, j; pd.x = (extent.x + otherExtent.x) - (other.getPosition().x - getPosition().x); // penetration in X - need to double check this pd.y = (extent.y + otherExtent.y) - (other.getPosition().y - getPosition().y); // penetration in Y correction.y = (std::max(pd.x-slop,0.00f) / (inverse + inverseOther))* percentage * normal.x; // correction based on the max of pen - by the slop. Percentage for overlap correction.y = (std::max(pd.y-slop,0.00f) / (inverse + inverseOther))* percentage * normal.y; j.x = -(1.f + e) + (minus(other.vel).dotProduct(normal)) / inverse + inverseOther; j.y = -(1.f + e) + (minus(other.vel).dotProduct(normal)) / inverse + inverseOther;From here I apply the code to my velocity in Y using j.y + correction.y, this in turn results my dynamic object resting on my static object with a little bit of bounce, which is wrong. It needs to be resting there perfectly so allow clean movement. Little stuck on what to do next.