Advertisement

Handling collisions with multiple bodies and unwanted collision with internal edges

Started by March 03, 2015 01:45 PM
11 comments, last by PunCrathod 9 years, 11 months ago

Oh, i think i get it. We can determine the t as the dot prosuct of velocy and penetration vector devided by penetration vector length. Yeah, that must work if the body do not penetrate too deep so the minimum transaltion vector is calculated on the right (first intersected) edge. Also, i think it will not work for circles. Anyway, thank you!

But what if the blue body moves straight from up to down?

Advertisement

Sorry I made a mistake in the calculation of t. The length of the penetration vector was supposed to be divided by the y component of rotatedvelocity.

Also I chose the vector (0,1) for the surfacenormalrotation so we can use the y component of the rotatedvelocity. You can use vector (1,0) if you want but then you need to use x component from the rotatedvelocity. This rotation is done so we can treat the surfacepenetration as an axis aligned vector so we can compare a single component from velocity vector to the length of the surfacepenetration.

Also in the unlikely event where t happens to be larger than 1 or rotatedvelocity.y is 0 then the chosen surface was invalid and you need to choose a new one. This can happen if we approach from an angle that is too steep compared to the penetrationvector wich means that blue could not have come from that direction in the firstplace. If you can't find a surface that results with t between 1 and 0 then blue was already inside red before it even moved.

Please note that the only valid surfaces are those that are between two adjacent corners of blue or two adjacent corners of red if we are evaluating surfaces of blue. It must be done both ways or otherwise you miss the collisions where a corner of red is inside blue

i think it will not work for circles

This does work on circles. Altough it can require multiple iterations(solve t and move blue backwards a lot of times until it finally is outside) and could take a long time but it will eventually get there.

But what if the blue body moves straight from up to down?

This shouldn't require any special handling.

Oh and because floats and doubles(64bit floats) can be a bit inaccurate at times you may need to modify the calculation of t by adding a little padding.


float t=0.001+abs(surfacepenetration.length/rotatedvelocity.y)

.

Another thing that comes to mind is that when choosing the surface you could try to optimize it by choosing a surface where the angle between the surfacepenetration and velocity is closest to pi radians or 180 degrees instead of the shortest one. In most cases they are the same but there are some cases where t will be over 1 if you use the smallest penetration length and in these cases choosing a surface where the angle between surfacepenetration and velocity was closest to 180 degrees would have been the correct one.

Also instead of checking if a surface is between two adjacent corners you can just check if the angle between the surfacepenetration and velocity is over pi/2 radians or 90 degrees as that indicates that blue is approaching the surface from the wrong side.

Checking the angle instead of penetrationlenth also fixes this.

that must work if the body do not penetrate too deep so the minimum transaltion vector is calculated on the right (first intersected) edge

Edit: Noticed that choosing the surface with the angle would make incorrect choises in some cases. But checking if the angle between surfacepenetration and velocity is between 1/2pi and 3/2pi radians or 90 and 270 degrees does fix the case where blue made it deep enough to make the penetration to the otherside be smaller than the side it came from.

This topic is closed to new replies.

Advertisement