Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Creating HingeJoint2d

Discussion in '2D' started by UnityJosh, Mar 5, 2015.

  1. UnityJosh

    UnityJosh

    Joined:
    Mar 5, 2015
    Posts:
    7
    How can I create HingeJoint2d at runtime?

    I need to be able to grab on surfaces and let go, so I need to be able to do this with script.

    Hope someone knows how.

    Thanks
     
  2. UnityJosh

    UnityJosh

    Joined:
    Mar 5, 2015
    Posts:
    7
  3. UnityJosh

    UnityJosh

    Joined:
    Mar 5, 2015
    Posts:
    7
    Running in unity 5 this codes not working, any ideas?

    varlegEndPos:Vector2;

    varlegRot = legLeft.transform.rotation.eulerAngles.z;

    legEndPos.x = legLeft.transform.position.x + (Mathf.Cos(((legRot-90))*(Mathf.PI/180.0))*(0.12));
    legEndPos.y = legLeft.transform.position.y + (Mathf.Sin(((legRot-90))*(Mathf.PI/180.0))*(0.12));

    legLeftHinge = legLeft.AddComponent.<HingeJoint2D>();

    legLeftHinge.anchor.x = 0;
    legLeftHinge.anchor.y = -0.12;

    legLeftHinge.connectedAnchor = legEndPos;