# Help with Impulse resolution and position correction

This topic is 2051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Fixed my issue Edited by Tweezy

##### Share on other sites

Not totally sure how you get your normals, trry something like this:

void Bound3vsBound3(vec2& correction, bound3 a, bound3 b)
{
// simple lookup table for the normals
vec2 normals[4] =
{
vec2(1,0), vec2(0,1), vec2(-1,0), vec2(0,-1);
}

float overlapx = min(b.max.x, a.max.x) - max(b.min.x, a.min.x);
float overlapy = min(b.max.y, a.max.y) - max(b.min.y, a.min.y);

if(overlapx > overlapy) // least penetration is along y
{
correction = a.min.y < b.min.y ? normals[1] * overlapy :normals[3] * overlapy;

}

else // least penetration is along x
{
correction = a.min.x < b.min.x ? normals[0] * overlapx : normals[2] * overlapx;
}
}

Edited by Doublefris

##### Share on other sites
Ahh okay. So the vector lookup table is for each normal coming off each side, understood. The overlap in x is taking the min of the two points, taken away from the max of the other. Same for the overlap in y.

Then, the two if statements are comparing the axis of least penitration. Gotcha. Once thing I am a little confused about, what are the "?" and ":" meant to represent?

Update

Never mind, they are ternary operators. Cheers Edited by Tweezy

##### Share on other sites

I noticed I made some errors when posting that code, tell me if you got everything to work :p, for the record I didn't test anything though I did just now make some changes to it.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 20
• 20
• 11
• 9