Joints Configured from Script do not work properly? $20 reward

I desperately need to be able to create joints via script. Currently I add and then set them up and they sort of work but something is clearly wrong, Motion and Angular Motion that are supposed to be locked are not locked, PositionSpring can only add a weak amount of force and position damper actually reduces that force without actually adding any damper.

Duplicates of these assemblies actually get progressively worse. I've tried setting .active to false just before and after .AddComponent with no effect. I have the same problem instantiating prefabs with joints, and creating joints via the editor with the game running.

Is there no way to add a Configurable Joint with the game running?

$20 Bounty for a solution to this.

Hi,

Totally feasible. I made a demo last year with an excavator fully scripted, building joints and setting them up on the fly.

Bye,

Jean

I’m actually having a similar issue, but I have got as far as adding the joint. It’s just the drive settings etc just dont ‘stick’.

Here is my code that adds a config joint o.k. It’s just that setting the angularXDrive and spring dont seem to do anything.

You can download my test scene here, it may be a good starting point. At least the joints are being added!

If you figure a way to make the angularXDrive and spring stick when done through script, please let me know!!

Dave

I do it like this (in a collision example):

`
function OnTriggerEnter(collision : Collider) {

	var joint : FixedJoint = gameObject.AddComponent(FixedJoint);
	joint.connectedBody = collision.gameObject.rigidbody;
	joint.breakForce = 250;
	joint.breakTorque = 250;

}
`

Don’t create and add a joint from scratch, let AddComponent(FixedJoint) create it and return it, then define it’s values and there you are. In this example, it’s working with a fixed joint, but I tested it out and it’s working with any of the predefined ones.

I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update. It is a bad idea to mess with a Quaternion directly. You should set XYZ in Euler angles with a vector3.
public Vector3 Vec1; Then you set your Quaternion with it, this way: private Quaternion QVec1; QVec1 = Quaternion.Euler (Vec1); QVec1 would be your set Quaternion with the angles you wish it to have. This is my vid on the subject you ask about, if you wish to check it out. Link: ConfigurableJointScript 1
The vid tells how to properly set TargetRotation within a script, and have it work!
Hope this helps. Oh’ you can keep you $20 if it does help you. :slight_smile: