Headlight issue and it's not the ballasts

So my headlights are having issues. Especially the right one which keeps going out whenever I turn or hit some bumps.

I replaced both ballasts and the problem is still persisting. I don’t think it’s the bulbs as they don’t turn off if I’m just idling.

Anyone ever come across a problem with the swivel mechanism? I’m dreading replacing the entire headlights as those are not cheap.