I’m trying to get a simple ConfigurableJoint working, I’d like it to just move a Cube to another object’s position. I’d like to get this working first, then go from there to get this custom joint working as needed.
I’ve tried many different things and the Cube just ends up flying off into space, moving in circles, etc… I’ve been stuck on this problem for days now and cannot find any helpful examples online, and the Unity documentation sucks when it comes to Configurable Joints.
Expected results… the Cube should just move toward the target position, using the spring/damper values, and being obstructed by any other physics objects that it encounters along the way.
I know I can easily just add forces through script to push it towards the target, but I don’t want to drive this through script because I need to add other constraints to this joint once this is working.
public Transform target;
private ConfigurableJoint configJoint;
void Start()
{
ConfigurableJoint j = gameObject.AddComponent<ConfigurableJoint>();
JointDrive d = new JointDrive();
d.mode = JointDriveMode.Position;
d.positionDamper = 1f;
d.positionSpring = 20f;
j.xDrive = d;
j.yDrive = d;
j.zDrive = d;
j.targetPosition = target.position;
configJoint = j;
}
void FixedUpdate()
{
configJoint.targetPosition = target.position;
}