Configurable Joint with script - not working with script, but o.k if done in editor!? bug?

Hi,

I’m adding a configurable joint using script. The goal is to link objectB to objectA and set its target rotation with spring, effectively working like a springy hinge joint but on all axis.

All is fine, apart from the angular drive mode settings that are being applied do not seem to be ‘applied’. Everything shows up in the editor as if it’s applied, (as in, angularXDrive and angularYZDrive is set to position, spring is on 20) but it just isn’t behaving as if those settings ARE on.

However, if I apply the exact same settings using the editor at runtime, then it behaves correctly. Totally weird!

Here is the scene so you can see what I mean.

jointtest.zip

To test, hit play, click the secondBone whilst it’s playing, and notice the angularXDrive and angularYZDrive and spring for each one. All seems to be there, but it’s not behaving.
Press stop.
Now, open setupjoints.cs and rem out line 24 to 30. (the bit that sets the drive modes)
Hit play, and now set the drive modes manually in runtime, as is it specified in script, so:
set angularXDrive to ‘position’, spring 20
set angularYZDrive to ‘position’, spring to 20.
It should have now ‘sprung’ to 90 deg as intended, but there is no difference in what you have now, to what is being set in script!. Same settings.!!?!

I hope this makes sense, and I hope I havent missed something blatently obvious!! (I’m tired!) but it’s certainly got me stumped!

Any help would be appreciated,

Many thanks :smiley:

Dave

Thee ‘maximum force’ property is defaulted to 0 on a new JointDrive created in code.

If you set a value for maximum force of your JointDrive in code, it will move the spring as required.

        JointDrive secondBoneJointDrive = new JointDrive();
        secondBoneJointDrive.mode = JointDriveMode.Position;
        secondBoneJointDrive.positionSpring = 20;
        secondBoneJointDrive.maximumForce = 20;
        secondBoneJoint.angularXDrive = secondBoneJointDrive;
        secondBoneJoint.angularYZDrive = secondBoneJointDrive;