[ad_1]
You want to regulate the anchor(s). Note, that they’re outlined within the native coordinates, relative to the proprietor object. There are two anchors: ConfigurableJoint.anchor and ConfigurableJoint.connectedAnchor. You can alter both one, however when you create the our bodies in autoConfigureConnectedAnchor mode, then it might be difficult to determine easy methods to alter which anchor.
I’d counsel to no depend on the automated habits and set each anchors manually when creating the joint. This method you may know precisely how and what to regulate.
Setup the joint like this:
// Given:
GameObject hingeObject;
GameObject ballObject;
// Then:
var joint = hingeObject.AddComponent<ConfigurableJoint>();
joint.autoConfigureConnectedAnchor = false;
ballObject.remodel.LookAt(hingeObject.remodel); // Optional.
joint.connectedBody = ballObject.GetComponent<Rigidbody>();
joint.anchor = Vector3.zero;
var initDistance = Vector3.Distance(hindgeObject.remodel.place, ballObject.remodel.place);
// ATTENTION! It's essential to know what axis your joint makes use of!
// If does not work, attempt to transfer initDistance to X or Y.
joint.connectedAnchor = new Vector3(0, 0, initDistance);
Now altering the space is trivial:
// Don't neglect about axis.
joint.connectedAnchor = new Vector3(0, 0, newDistance);
[ad_2]