How to set a configurable joints initial rotation

Hi all, I am currently working on a system where an object that has a velocity, can hook onto another (static) object and thus swing around it. Since I want to use Physics, I came down to a configurable joint, but I am running into a small problem.

The initial rotation of when I add the joint, makes the object that hooks onto the other, teleport before working as expected (see GIF for visuals). Am I missing something that can fix this?

link text

I have tried to use a connected anchor and setting the (connected) anchor myself, yet it doesn’t solve my problem. Below is the code used to instantiate and configure the joint

        grappleJoint = movementObject.gameObject.AddComponent<ConfigurableJoint>();
        grappleJoint.autoConfigureConnectedAnchor = false;

        Vector3 grappleJointAnchorPosition = grappleJoint.transform.position - grappleAnchorTransform.position;

        grappleJoint.anchor = grappleJointAnchorPosition;
        grappleJoint.connectedAnchor = grappleAnchorTransform.position;

        grappleJoint.xMotion = ConfigurableJointMotion.Locked;
        grappleJoint.yMotion = ConfigurableJointMotion.Locked;
        grappleJoint.zMotion = ConfigurableJointMotion.Locked;

Thanks in advance for any help :slight_smile:

For anyone that finds this topic in the future, I managed to fix it by having the configurable joint being a component on the object all the time, but instead of destroying it when not using, just set the x, y and zMotion to free. Next make sure that you calculate the anchor point correctly. I ended up with the following in order to fix it:

Vector3 grappleJointAnchorPosition = grappleJoint.transform.InverseTransformPoint(grappleAnchorTransform.position);

grappleJoint.anchor = grappleJointAnchorPosition;
grappleJoint.connectedAnchor = grappleAnchorTransform.position;

grappleJoint.xMotion = ConfigurableJointMotion.Locked;
grappleJoint.yMotion = ConfigurableJointMotion.Locked;
grappleJoint.zMotion = ConfigurableJointMotion.Locked;

grappleJoint.connectedBody = grappleAnchorRigidbody;