예제 #1
0
    void CreateSpringJoint(int bondOrder, Atomic otherAtom)
    {
        // create spring joint
        SpringJoint bond = gameObject.AddComponent <SpringJoint>();

        bond.autoConfigureConnectedAnchor = false;
        bond.connectedAnchor = new Vector3(0, 0, 0);
        bond.anchor          = new Vector3(0, 0, 0);
        bond.connectedBody   = otherAtom.GetComponent <Rigidbody>();
        bond.spring          = bondOrder * BondSpringConstant(otherAtom);
        bond.damper          = 0.5f;
        bond.minDistance     = 0.0f;     //0.0105f;
        bond.maxDistance     = 0.0f;     //0.0112f;

        // FIXME just guessed at what would break a spring. 0.25 of energy to stretch spring 1nm?
        // But if it's a double or triple bond, it breaks at quarter, half, and 3/4 of meter force
        bond.breakForce = bondOrder * BondSpringConstant(otherAtom) / 1.0f;
        Debug.Log(string.Format("Creating spring with break: {0}", bond.breakForce));
    }