Rotation issues with hinge joint targetPositition - Help!

I’m using hinge joints to copy rotational motion to a ragdoll-based character from an animated model. This works very well for most of the joints, but when I get to the legs and feet, a problem arises. I believe my script correctly copies the rotation to the targetPosition property of the hinge joint (the angle in degrees of the targetPosition matches the angle of the body part in the animated model). However, the resulting rotation of the ragdoll’s corresponding body part (legs or feet) is off from the animated model by greater than 90 degrees.

JointSpring js = HingeJoint.spring;

                js.targetPosition = animatedPart.transform.localEulerAngles.x;

                if (js.targetPosition > 180)
                    js.targetPosition = js.targetPosition - 360;
                               
                HingeJoint.spring = js;

This can be repeated for each axis or inverted if the rotation is negative but should be positive.
Does anyone know what the issue is? I’ve tried nesting the animator body parts in question (so that the local rotation of the legs/feet starts at 0) and that seemed to work, but it breaks the hierarchy of the animated model, rendering my animations useless and destroying my prefab. I’ve also tried using localRotation instead of localEulerAngles, but this produced similar, strange results.
I considered reworking the script to use configurable joints instead, but I thought I might run into the same issue. Anyway, a solution would be greatly appreciated; I’ve really hit a roadblock on this one.
Thanks in advance!

Use OnDrawGizmos to DrawRay in the direction of your animated model’s local rotation. You need to find out what sort of offset your actual model has in relation to the internal rotation. You should then offset your hinge joints to match.

If you’re not willing to recreate the model and animation the way you’re expecting, you’ll need to deal with those inconsistencies in your code.