Example #1
0
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.GetComponent("KinMol") as KinMol == lastBindableMolecule)
     {
         lastBindableMolecule = null;
     }
 }
Example #2
0
    // REACT
    private void OnTriggerEnter(Collider collider)
    {
        if (age > inertTime)
        {
            KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;
            if (molecule)
            {
                //Debug.Log("Collided with another molecule");
                if ((type == 0 && molecule.type == 1))                // && (myKinBind && molecule.myKinBind))
                {
                    var averagePosition = (collider.gameObject.transform.position + gameObject.transform.position) / 2f;

                    {
                        // deal with enzyme bound
                        if (myKinBind)
                        {
                            myKinBind.ReleaseMol();
                        }
                        if (molecule.myKinBind)
                        {
                            molecule.myKinBind.ReleaseMol();
                        }
                    }

                    // Destroy reactant A + B
                    Destroy(gameObject);
                    Destroy(collider.gameObject);
                    // Create product C
                    mySpawner.SpawnNewMolecule(3, averagePosition);
                }
            }
        }
    }
Example #3
0
 private void OnTriggerEnter(Collider collider)
 {
     if (collider.gameObject.GetComponent("KinMol") as KinMol)
     {
         testMolecule = collider.gameObject.GetComponent("KinMol") as KinMol;
         DoBindCheck(testMolecule);
     }
 }
Example #4
0
    public void SpawnNewMolecule(int molType, Vector3 position)
    {
        KinMol _mol01 = Instantiate(molecule, position, Quaternion.identity);         //, zoneGO.transform);

        _mol01.gameObject.name = "mol_" + molCount;
        _mol01.type            = molType;
        _mol01.mySpawner       = this;
        _mol01.scale           = 0.04f;
        _mol01.zoneGO          = zoneGO;

        KinDiffuse _diffuse = _mol01.gameObject.GetComponent("KinDiffuse") as KinDiffuse;

        _diffuse.zoneGO = zoneGO;

        molCount++;
    }
Example #5
0
    //private void OnTriggerEnter(Collider collider)
    //{
    //	{
    //		KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;
    //		if (molecule)
    //		{
    //			if (molecule.type == 3)
    //			{
    //				if ( Vector3.Dot(transform.right, (molecule.transform.position - transform.position)) > 0f)
    //				{
    //					molecule.GetComponent<Rigidbody>().AddForce(transform.right * 0.25f, ForceMode.Impulse);
    //				}
    //			}
    //		}
    //	}

    //}

    private void OnTriggerStay(Collider collider)
    {
        KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;

        if (molecule)
        {
            if (!molecule.myKinBind)
            {
                if (molecule.type == 3)
                {
                    Vector3 pushDir = -transform.right;
                    float   dot     = Vector3.Dot(pushDir, (molecule.transform.position - transform.position));
                    if (dot > 0f)
                    {
                        molecule.GetComponent <Rigidbody>().AddForce(pushDir * 0.01f, ForceMode.Impulse);
                    }
                    else if (dot < 0f)
                    {
                        molecule.GetComponent <Rigidbody>().AddForce(-pushDir * 0.01f, ForceMode.Impulse);
                    }
                }
            }
        }

        if (!molecule)
        {
            KinDiffuse diffuse = collider.gameObject.GetComponent("KinDiffuse") as KinDiffuse;
            if (diffuse)
            {
                //if (molecule.type == 3)
                {
                    Vector3 pushDir = -transform.right;
                    float   dot     = Vector3.Dot(pushDir, (diffuse.transform.position - transform.position));
                    if (dot > 0f)
                    {
                        diffuse.GetComponent <Rigidbody>().AddForce(pushDir * 0.01f, ForceMode.Impulse);
                    }
                    else if (dot < 0f)
                    {
                        diffuse.GetComponent <Rigidbody>().AddForce(-pushDir * 0.01f, ForceMode.Impulse);
                    }
                }
            }
        }
    }
Example #6
0
    public void ReleaseMol()
    {
        if (boundMol)
        {
            KinMol _lastBoundMolecule = boundMol;

            isBinding          = false;
            boundMol.myKinBind = null;
            boundMol           = null;

            if (lastBindableMolecule && (lastBindableMolecule != _lastBoundMolecule))
            {
                DoBindCheck(lastBindableMolecule);
            }
        }
        else
        {
            Debug.LogError("ReleaseMol() - boundMol NULL");
        }
    }
Example #7
0
    private void DoBindCheck(KinMol molecule)
    {
        //if (!isBinding)
        {
            //KinMol molecule = collider.gameObject.GetComponent("KinMol") as KinMol;
            if (molecule)
            {
                if (molecule.type == typeToBind)
                {
                    //bool displace = Random.Range(0f, 1f) > 0.9f;
                    if (!isBinding)                    // || displace)
                    {
                        // if I am already binding then release my bound molecule
                        if (isBinding)
                        {
                            boundMol.myKinBind.ReleaseMol();
                        }

                        // if molecule is already bound to another site - force release
                        if (molecule.myKinBind)
                        {
                            molecule.myKinBind.ReleaseMol();
                        }

                        BindMol(molecule);
                        //var averagePosition = (collider.gameObject.transform.position + gameObject.transform.position) / 2f;
                        //mySpawner.SpawnNewMolecule(3, averagePosition);

                        //Destroy(gameObject);
                        //Destroy(collider.gameObject);
                    }
                    else
                    {
                        lastBindableMolecule = testMolecule;
                    }
                }
            }
        }
    }
Example #8
0
 private void BindMol(KinMol molecule)
 {
     isBinding          = true;
     boundMol           = molecule;
     molecule.myKinBind = this;
 }