10 hours ago, Rutin said:
I'm asking what 'code' you have written attempting to solve the problem. The solution is pretty straight forward, you never allow movement that would cause any overlapping to begin with by checking for collision on each tick. If movement would cause an overlap you can also offset the amount back to the edge so the object will be right up against the second object. Now if you have code written and you're still getting this problem we can look at that.
Is this for school?
It's just my personal interest. It has nothing to do with school. How can I show you my code?
Copy and paste, screenshot, or...
float backIsDivide(Polygon * poly1, Polygon * poly2, float t1, float t2)
{
float result = (t2 + t1) / 2.0;
poly1->changeLocation(result - t2);//the object back
poly2->changeLocation(result - t2);
if (!CollisionDetection::detection(poly1,poly2)
)
{
//forwardIsImpact is similar to backIsDivide
return forwardIsImpact(poly1, poly2, result, t2);
}
else
{
if (t2 - t1 <= timePrecision)
{
return result;
}
return backIsDivide(poly1, poly2, t1, result);
}
}
//After the object has moved...
if (CollisionDetection::detection(poly1, poly2))
{
float collisionTime = duration;
if (collisionTime > timePrecision)
collisionTime = backIsDivide(poly1, poly2, 0, duration);
//The two objects are now in an overlapping state...
//I use the sum velocity (v+ ω× r) of the overlapping vertices as the slope to
//calculate the intersection point between the overlapping vertex and the edge of
//another object. The point of intersection is the point of contact. Finally, move
//objects so that their edges and vertices come into contact, and change the speed of the object.
}
This seems to solve the problem of separation, but if two objects next to each other collide with another object at the same speed, because of recursion, the colliding object will collide with the object next to it... ..
I hope you can give me a suggestion