Leg bones twisting backwards when moving leg up
When you move the foot up above a certain threshold then your pole target is below the line connecting the foot and hip joints. The knee joint will then orient down to the pole target as best as it can.



To fix this you have to move the pole target forwards and/or upwards so that it's above the line again.

About the pole target

The main part of the inverse kinematics constraint is to calculate the angles of upper and lower leg so that the leg points to the foot without there being any disconnected parts. Without a pole target there would be an infinite number of orientations that would achieve this. In this example this would leave the knee rotating around the axis from hip to foot – the red line drawn above.

The pole target works in a way that can be thought of as spanning a rubber band or spring between the pole target. The knee now rotates around the hip-foot-axis so that the distance between knee and pole target is minimized. In the screenshot above the pole target is very close to the axis, so a real rubber band probably wouldn't be very efficient. But nonetheless the distance between knee and pole target is lower here when the knee points backwards than it would be if the knee would be pointing forwards. If you pull the pole target around the axis – or, speaking for the side view, above the line and more far away – the knee will be pulled over to the other side of the axis as well.