I've been trying everything to get a 2D distance joint working in Unity. I want free rotation to both the body with the joint and the connected body, I also need mass and other constraints adhered to, such as fixing a rigidbody's position. I've tryed for days now, no luck configuring any joint type. Tryed a verlet constraint using:
float xDistance = hinge.transform.position.x - target.transform.position.x;
float yDistance = hinge.transform.position.y - target.transform.position.y;
float newdistance = Mathf.Sqrt( xDistance * xDistance + yDistance * yDistance );
float con = ( newdistance - maxDistance) / newdistance;
Vector3 moveTarget = new Vector3( xDistance * 0.5f * con , yDistance * 0.5f * con, 0.0f );
hinge.rigidbody.MovePosition( hinge.transform.position - moveTarget );
target.rigidbody.MovePosition( target.transform.position + moveTarget );
But this doesn't take into account mass/force or any fixtures. You can see here I want movement on the X/Y and rotation only on Z.
Help?