Search code examples
c#unity-game-enginephysicsragdoll

Is there a way to change the values of the CharacterJoint component (eg. hightwistlimit) in a script in unity?


I want to change the various joint angles of the characterjoint with a script in runtime. But I didn't find a way to access the angles via script.

I found the scripting API for characterjoints here:https://docs.unity3d.com/ScriptReference/CharacterJoint.html But I'm still not sure, for example how to change the swingLimit1 value of a specific characterjoint.

I'm using this code to call the functions of a characterjoint but "jnt" doesn't have any of those functions.

CharacterJoint[] jnts;

    void Start()
    {
        jnts = GetComponentsInChildren<CharacterJoint>();    
    }

    void Update()
    {
        foreach (Joint jnt in jnts)
        {
            jnt.
        }
    }

Solution

  • Oh god I feel like an idiot. The problem was I used "Joint" instead of "CharacterJoint" in the foreach loop. This is the correct version:

    void Update()
        {
            foreach (CharacterJoint jnt in jnts)
            {
                jnt.swing1Limit
            }
        }
    

    Thanks for the help!