- Home /
Anchor at connectedbody
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;
}
}
}
Answer by Aldwoni_legacy · Jun 28, 2011 at 08:24 AM
I used a Configurable joint and added the joint at the other cube. More information can be found: http://forum.unity3d.com/threads/41147-Moving-hinge-joint-in-a-script-has-no-effect
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Problem assigning hj.connectedBody 0 Answers
Hinge joint connected body scripting issues 1 Answer
How to tell if two objects are right next to each other in a 2d game? 2 Answers
How can i auto Position my Game Object? 0 Answers