- Home /
changing the connectedBody of a joint on another GO
i've been at this for 2 hours atleast and i cant see what im missing , i checked the syntax and the references but still it just wont work
i need to set the connectedBody of a joint on another gameObject , this is my code
function Update (){
if(Input.GetButtonDown("p1pushl")){buttondown = true;}
if(Input.GetButtonUp("p1pushl")){buttondown = false;
StartCoroutine("dropgun");
}}
function OnCollisionEnter (c : Collision){
if(buttondown == true){
//if(!joint.FixedJoint&& !handsrfree){
var joint = c.gameObject.AddComponent(FixedJoint);//var joint =
joint.connectedBody=transform.rigidbody;
Debug.Log(joint.connectedBody);
}}
What is the exact error you are getting? Try specifically setting the type of the 'var joint' line- so that it goes more like this
var joint : FixedJoint = c.gameObject.AddComponent(FixedJoint);
(The fact that it is possible to do this at all without explicitly stating the type is part of what annoys me about javascript...)
just tried and still nothing , the debug log always returns null and the object is always remains connected to the scene
the problem is not adding the component to the object , that works just fine , what dosent work is changing afterward , this line simply will not work no matter how i phrase it
joint.connectedBody=transform.rigidbody;
ive tried every single way to reference the rigidibody of the GO the script is in and none work , so i tried changing the reference used this way
c.gameObject.AddComponent(FixedJoint); var joint = c.gameObject.GetComponent(FixedJoint); joint.connectedBody=transform.rigidbody;
and still the object gets its joint and its connectedbody remains null
ive tried every permutation i can think of and made sure all capitalization was correct , can anyone see my mistake ?
dosent anyone know this ? every way ive tried to add the joint works fine but none of ways ive tried to do change the connected body will work
Your answer
![](https://koobas.hobune.stream/wayback/20220613010338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get the World position of a connectedAnchor? (2d) 1 Answer
Problems with sending multiple raycasts at once 1 Answer
How do you find a Joint from its connectedBody? 1 Answer
Tie objects together 5 Answers
Locomotion and Joints 0 Answers