changing the connectedBody of a joint on another gameObject

i’ve been at this for a day and a half at least and i cant see what im missing , i checked the syntax and the references ,everything should work but still it just wont.

i need to set the connectedBody of a joint on another gameObject to the gameObject the script is on , this is my code and it always results in adding the Fixedjoint and failing to change the connected body ,

i know i should get a reference to the joint when creating it but i even tried getting it manually to be sure that wasnt the problem,

im fairly sure the prblem isnt in getting witch rigidbody to attach it to but i still tryed every way i knew of attaching it to the rigidbody the script is in ,

does anyone have an idea what going on here ?

function Update (){

if(Input.GetButtonDown("p1pushl")){buttondown = true;}
if(Input.GetButtonUp("p1pushl")){buttondown = false;
StartCoroutine("dropgun");
}}

function OnCollisionEnter (c : Collision){
if(buttondown == true){
var joint = c.gameObject.AddComponent(FixedJoint);
joint.connectedBody=transform.rigidbody;
Debug.Log(joint.connectedBody);
}}

Ignoring your StartCoroutine, the code works fine for me.

I put the script onto a cube, dropped a sphere onto it, and if holding down the key then the sphere attaches to the cube with a fixed joint, and both fall together.

The only thing I can think of is that your object that has the script on it doesn’t actually have a rigidbody component.

oh my god ! its always something that simple isnt it ?

More often than not, yes! :slight_smile: