1
\$\begingroup\$

My player is at the moment an ArticulationBody setup that looks like the lower half of a person: a waist, two thighs, and two shins. I'm currently just implementing moving the thighs, and my code works fine for the left thigh. But, instead of OnRightLegPos() moving the right thigh, it moves the left shin.

I've run just about everything in my code through Debug.Log and all the values make perfect sense, so the only thing left I can assume is that there is a discrepancy between the ArticulationBody's indices and it's drive target List.

(I can link my unity project if that's worth looking at)

public class PlayerClass : MonoBehaviour
{
    private Transform _thighL;
    private Transform _thighR;
    private Transform _shinL;
    private Transform _shinR;

    private ArticulationBody _articulationBody;
    private List<float> _drTargets = new List<float>();
    private List<int> _dofIndices = new List<int>();

    private ArticulationBody _thighLJoint;
    private ArticulationBody _thighRJoint;
    private ArticulationBody _shinLJoint;
    private ArticulationBody _shinRJoint;
    
    

    // Start is called before the first frame update
    void Start()
    {
        _thighL = transform.Find("LThigh");
        _thighR = transform.Find("RThigh");
        _shinL = _thighL.transform.Find("LShin");
        _shinR = _thighR.transform.Find("RShin");

        _articulationBody = GetComponent<ArticulationBody>();
        _articulationBody.GetDofStartIndices(_dofIndices);
        _articulationBody.GetDriveTargets(_drTargets);

        _thighLJoint = _thighL.GetComponent<ArticulationBody>();
        _thighRJoint = _thighR.GetComponent<ArticulationBody>();
        _shinLJoint = _shinL.GetComponent<ArticulationBody>();
        _shinRJoint = _shinR.GetComponent<ArticulationBody>();
    }

    void OnLeftLegPos(InputValue value)
    {
        int ind = _dofIndices[_thighLJoint.index];
        _drTargets[ind + 1] = value.Get<Vector2>().y;
        _drTargets[ind + 2] = value.Get<Vector2>().x;
        _articulationBody.SetDriveTargets(_drTargets);
    }
    
    void OnRightLegPos(InputValue value)
    {
        int ind = _dofIndices[_thighRJoint.index];
        _drTargets[ind + 1] = value.Get<Vector2>().y;
        _drTargets[ind + 2] = value.Get<Vector2>().x;
        _articulationBody.SetDriveTargets(_drTargets);
    }
}
```
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Well I never found the reason for the issue, but remaking my player object from scratch fixed the issue.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .