- Home /
Change length of fixed joint
I have 2 cubes connected to an Fixed Joint. Now I want to move one cube away from the other cube. (make the distance between the cubes bigger).
Is there a better solution than kill the fixed joint, change the distance and then create a new fixed joint?
Answer by Statement · Jun 06, 2011 at 12:22 PM
Maybe you could try changing from using a fixed joint to a configurable joint instead?
Configurable Joints are extremely customizable. They expose all joint-related properties of PhysX, so they are capable of creating behaviors similar to all other joint types.
is there a tutorial for using configurable joints?
Didn't the documentation provide enough information? I am unaware of any specific tutorial on them, but try google. "unity3d configurable joint tutorial". The documentation also suggest to experiment a bit to find the right feeling, and I think it's a good way to get to grip with it. I'd narrow down on the properties you're after, and try get those to work accordingly. When you found your set of variables you want to control, just write a script that change the settings as needed. I don't know if changing the setup of a joint require the delete/create method you described or not. Don't be afraid to play around a bit :)
maybe I don't look far enough but the only thing I can find is that people say " if any feature of Unity was deserving a video demonstration of it's functionality, it's Configurable Joints." with replies like " Indeed. A example project, with an accompanying video tutorial, to demonstrate what you should start messing with, in order to learn quickly, would be good."
I'm currently trying to create a FixedJoint from a Configurable Joint.
I've made something like a Fixed joint with a Configurable joint, but I can't change the distance between them.
Finally found an solution for my problem, with help from: http://forum.unity3d.com/threads/41147-$$anonymous$$oving-hinge-joint-in-a-script-has-no-effect
Answer by Owen-Reynolds · Jun 07, 2011 at 11:27 PM
Turns out any attempt to move the hinged object using transform.position will be snapped back to where it started. you can't disable the hinge, but you can unscrew the far end:
// Save end of hinge, then unscrew it:
Rigidbody RB = transform.hingeJoint.connectedBody;
transform.hingeJoint.connectedBody = null;
// Tricky, since anchor is local. No easy way to move it "world backwards":
//transform.hingeJoint.anchor += Vector3.forward * 0.1f;
// Can now move unconnected hinge:
transform.position -= Vector3.forward*0.2f;
transform.hingeJoint.connectedBody = RB; // screw it back in
What did I do wrong?
var aap : GameObject;
var beer : GameObject;
script = this.gameObject.GetComponent(speler);
aap = script.aap;
beer = script.beer;
function FixedUpdate(){ verticaal = Input.GetAxis(script.verticaal);
if(verticaal != 0)
{
var joint : FixedJoint;
joint = aap.gameObject.GetComponent(FixedJoint);
Destroy(joint);
aap.rigidbody.velocity = Vector3(0,verticaal,0);
aap.AddComponent(FixedJoint);
joint.connectedBody = beer.rigidbody;
}
}
Like you implied, this "destroy then remake" method may not be the best approach. Lots of values you hand-tweaked need to be recreated on the new one.
but now the he can'f find his connectedBody back. Do you know a better approach?, I would like to know.
I solution looking a bit like your is almost working. I only need to get the anchor of the joint to be at the location of the connectebody.(I don't expect any errors after that but are not sure)
Answer by Ye · Feb 14, 2014 at 03:22 AM
Use configurable joint, linearLimit
ConfigurableJoint configurableJointComp = GetComponent(); SoftJointLimit softJointLimit = new SoftJointLimit(); softJointLimit.damper = 1f; configurableJointComp.linearLimit = softJointLimit;
Answer by BurningKrome · Feb 24, 2015 at 10:18 AM
In addition to the above, defining the X-drive, y-drive, and z-drive in conjunction with a target position/velocity can be used to move the object to specific distances, creating a "length" to the joint arm. Be sure to set the x/y/z-drive spring, as this is what pushes the object out to the limit.
Answer by K0ST4S · Dec 24, 2018 at 09:26 PM
If it's 2D game, use Distance Joint 2D. You can write something like: joint.distance = yourDistance; or set EnableCollision and Max Distance Only for minimum distance.
Your answer
Follow this Question
Related Questions
Multiple conected bodies for joint? 0 Answers
how to move object with joint 2 Answers
Is it okay to give child objects rigidbodies? 0 Answers
Hinge joints not reaching target position 1 Answer
Move mechanical arm with mouse 0 Answers