Collision resolution in tight spaces

I’m trying to implement collision detection on my character controller so I’m using the pushback method.
Everything works fine except when I have two colliders that are placed in a similar way to the image, making a really tight “angle”.
Those two colliders could be two box colliders, or any other kind of colliders, the issue is that, after applying the pushback vectors the player collider is still overlapping with one or both of the “walls”.
This results in a sort of jittery back and forth movement as the script solves the collisions frame by frame until there are no more collisions.

Here’s an awesome ms paint drawing that sums up the situation.
66091-collision.png

Is there a better way to solve this kind of collisions? A quick work around would be to repeat the collision detection more times per frame untill the collision is completely solved but this doesn’t sount to me as a good solution.

Thanks!

Well, when adding all correction vectors with their proper magnitude together you get a new correction vector that has the correct direction, but the wrong magnitude. To get the correct magnitude you simply project the combined correction vector onto one of the original correction vectors. The magnitude of that projected vector would be smaller than the initial calculated magnitude that is needed to push the object away from that contact point. The ratio between the magnitude of the initial correction vector and our projected vector is the amount you need to scale the combined correction vector.

This should work in theory:

Vector3 A; // left correction vector
Vector3 B; // right correction vector
Vector3 C = A+B // combined correction vector
Vector3 P = Vector3.Project(C, A); // projected vector
C = C * A.magnitude / P.magnitude;

This also corrects the magnitude if you have a wide angle where the correction would be too large instead of too small.