Example #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);
    }
Example #2
0
    public HingeJoint2D AddJoint(BoneBridgeSnapToSocket socket)
    {
        switch (socket.typeOfEnd)
        {
        case BoneBridgeSnapToSocket.EndType.Left:
            return(!boneJoint?CreateJoint(socket, -90f, 90f, 2f) : null);

        case BoneBridgeSnapToSocket.EndType.Right:
            return(!boneJoint?CreateJoint(socket, 90f, -90f, -2f) : null);

        default:
            return(null);
        }
    }
    private void SnapTo(BoneBridgeJoint joint)
    {
        transform.parent.position = joint.transform.position + (transform.parent.position - transform.position);
        jointAttached             = joint;
        hingeAttached             = joint.AddJoint(this);
        BoneBridgeSnapToSocket snap = joint.GetComponent <BoneBridgeSnapToSocket> ();

        if (snap)
        {
            snap.jointAttached = jointAttached;
            snap.hingeAttached = hingeAttached;
        }

        SoundManager.Instance.PlaySFXClip(boneAttachSfx);
    }