How can I get the anchor of a Hingejoint at the position of the connectedbody?
I have 2 cubes. The red ones can move and the blue one only follows. The blue one has an HingeJoint and the connectedbody of the hingejoint is the red cube.
How can I make sure that the anchor of the connectedbody stay at the same position as the red cube?
function Update(){
verticaal = Input.GetAxis(script.verticaal);
if (Mathf.Abs(verticaal)<0.5)
{
verticaal = 0;
}
if(verticaal != 0)
{
transform.hingeJoint.connectedBody = null;
if(transform.position.y > 2 && verticaal < 0.5 ||transform.position.y < 23 && verticaal > -0.5)
{
transform.position += Vector3.up*verticaal;
transform.hingeJoint.connectedBody = redcube.rigidbody;
transform.hingeJoint.anchor.y = redcube.transform.localPosition.y - bluecube.transform.localPosition.y;
transform.hingeJoint.anchor.x = redcube.transform.localPosition.x - bluecube.transform.localPosition.x;
}
}
}