Need help rigging a mechanical leg joint

Hello there!
So I need a little bit of help rigging this mechanical leg:

I was able to make it so it works great if I simply drag the IK controller on the end tip of the leg, but once I try to tilt it by moving the knee target, it gets messy in the upper joint area:

I’m pretty sure what I need here is to add proper Transform Constraints controlling the joint bones rotation, but I just can’t figure out which bones should trigger those and in what particular way.
Also I’m pretty sure it absolutely must be possible to set up, since what I’m really trying to do here is just to recreate an armature from a tutorial I was able to find on YouTube:

The problem is the tutorial in question is done in Maya and not Blender, so things work differently and I can’t figure it out.

Help would be much appreciated!
Here is my .blend file:
Leg Test.blend (531.2 KB)

1 Like

And it’s done.
Googling for mechanical arms/legs rigging didn’t get me anywhere, yet searching for Blender unijoint (universal joint) rig did bring up multiple tutorials with quite different approaches to the problem, of which this one proved to be the simplest to follow and overall the best one for me personally:

Actually contrary to what I thought after watching the Maya tutorial, in Blender Transform Constraints proved not to be the right choice. Instead all I needed was a couple of Locked Track Constraints and a couple of extra bones.
Here is the working .blend file for anyone interested:
Leg Test.blend (533.7 KB)