access specific config joints out of multiple ones on the same object?

Hey everyone,

I have a sphere with three cylinders attached. I want each other these to be able to move in the y and z axis. So I have three config joint components attached to the sphere with each cylinder a connected body. This works fine only using the inspector. How do I access each config joint through code though? All I need to is to control angular velocity through code.

I have tried…

GameObject cyl_br_2;

cyl_br_2 = GameObject.Find(“Cyl_BR_2”);

cyl_br_2.GetComponent();

cyl_br_2.targetAngularVelocity.z += .1;

and…

ConfigurableJoint configJoint_1 = new ConfigurableJoint();

configJoint_1.targetAngularVelocity.z-= .1;

since I can’t rename the config joint component and the cylinder itself doesn’t have the component on it, how do I control all three config joint components on the sphere individually?

Thanks :slight_smile:

If I understand your setup, you have a central sphere and three cylinders, each with a configurable joint with each of their connected body being the sphere. If you have three configurable joints attached to your sphere, I would switch that up and put them on the cylinders. It makes it easier on yourself.

You were so close.


GameObject cyl_br_2;
ConfigurableJoint cyl_br_joint_2;

cyl_br_2 = GameObject.Find(Cyl_BR_2);
cyl_br_joint_2 = cyl_br_2.GetComponent(ConfigurableJoint);
cyl_br_joint_2.targetAngularVelocity.z += .1;

More info on get component