I am having a strange problem converting some Unity javascript to C#. Let me disclose that I am a kompleat C# noob (and really not very good with the js either). Basically, I am creating a ragdoll programatically, which works perfectly in javascript. But in C#, I cannot figure out why I cannot set the limits for the CharacterJoint’s SoftJointLimits.
Here is the relevant working js snippet:
Unity Javascript code:
spine.AddComponent( "CharacterJoint" );
spine.GetComponent(CharacterJoint).connectedBody = hips.rigidbody;
spine.GetComponent(CharacterJoint).anchor = Vector3( 0.2, 0, 0 );
spine.GetComponent(CharacterJoint).axis = Vector3( 0, 1, 0 );
spine.GetComponent(CharacterJoint).lowTwistLimit.limit = -10;
spine.GetComponent(CharacterJoint).highTwistLimit.limit = 30;
spine.GetComponent(CharacterJoint).swingAxis = Vector3( 1, 0, 0 );
spine.GetComponent(CharacterJoint).swing1Limit.limit = 10.0;
spine.GetComponent(CharacterJoint).swing2Limit.limit = 0.0;
And here is the equivalent C#, which, if I’ve understood the docs correctly, should work the same as above:
C# code:
spine.AddComponent( "CharacterJoint" );
CharacterJoint spineJoint = (CharacterJoint)spine.GetComponent(typeof(CharacterJoint));
spineJoint.connectedBody = hips.rigidbody;
spineJoint.anchor = new Vector3( 0.2f, 0.0f, 0.0f );
spineJoint.axis = new Vector3( 0.0f, 1.0f, 0.0f );
SoftJointLimit spineLTL = spineJoint.lowTwistLimit;
spineLTL.limit = -10.0f;
SoftJointLimit spineHTL = spineJoint.highTwistLimit;
spineHTL.limit = 30.0f;
spineJoint.swingAxis = new Vector3( 1.0f, 0.0f, 0.0f );
SoftJointLimit spineS1L = spineJoint.swing1Limit;
spineS1L.limit = 10.0f;
SoftJointLimit spineS2L = spineJoint.swing2Limit;
spineS2L.limit = 0.0f;
I’ve attached two images showing the CharacterJoint settings while the app is running with the javascript and the C# script. The C# implementation seems to retain the default Twist and Swing limit values, which leads me to believe that I’m not actually setting them with the above code.
Please help a noob?
Thanks very much in advance!