Beispiel #1
0
    HingeJoint2D CreateJoint(BoneBridgeSnapToSocket socket, float lowerAngle, float upperAngle, float anchorOffset)
    {
        if (GetComponent <Rigidbody2D> ())
        {
            boneJoint = gameObject.AddComponent <HingeJoint2D> ();
        }
        else
        {
            boneJoint        = transform.parent.gameObject.AddComponent <HingeJoint2D> ();
            boneJoint.anchor = new Vector2(anchorOffset, boneJoint.anchor.y);
        }

        socket.GetComponent <BoneBridgeJoint> ().boneJoint = boneJoint;

        Rigidbody2D rigBody = socket.transform.parent.GetComponent <Rigidbody2D> ();

        rigBody.velocity        = Vector2.zero;
        boneJoint.breakForce    = jointBreakForce;
        boneJoint.connectedBody = rigBody;

        JointAngleLimits2D limits = boneJoint.limits;

        limits.min          = lowerAngle;
        limits.max          = upperAngle;
        boneJoint.limits    = limits;
        boneJoint.useLimits = true;
        return(boneJoint);
    }
 void Start()
 {
     startPos = transform.position;
     startRot = transform.rotation;
     leftJoint.GetComponent <BoneBridgeJoint> ().jointBreakForce  = jointBreakForce;
     rightJoint.GetComponent <BoneBridgeJoint> ().jointBreakForce = jointBreakForce;
 }