// Use this for initialization
    void Start()
    {
        particle = new HooksLaw.Particle();
        spring   = new HooksLaw.SpringDamper();

        particle.AddForce(new Vector3(9.807f, 0, 0));
    }
Beispiel #2
0
    void Start()
    {
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < colms; j++)
            {
                GameObject p = Instantiate(game, new Vector3(i * 5, -j * 5, 7), Quaternion.identity);
                p.AddComponent <ParticleBehaviour>();
                p.GetComponent <ParticleBehaviour>().particle = new HooksLaw.Particle(p.transform.position, Vector3.zero, 1);
                gameObject.GetComponent <SpringDamperBehaviour>().particles.Add(p.GetComponent <ParticleBehaviour>().particle);
                objects.Add(p);
            }
        }

        for (int i = 0; i < (colms * rows); i++)
        {
            particles[i].gravity = true;

            if (i % colms < colms - 1)
            {
                p1 = particles[i];
                p2 = particles[i + 1];

                Sd = new HooksLaw.SpringDamper(p1, p2);
                springDampers.Add(Sd);
            }

            if (i < (colms * rows) - colms)
            {
                p1 = particles[i];
                p2 = particles[i + (int)rows];

                Sd = new HooksLaw.SpringDamper(p1, p2);
                springDampers.Add(Sd);
            }

            if (i < (colms * rows) - colms && i % colms < colms - 1)
            {
                int bottom = i + (int)rows;
                int right  = i + 1;

                p1 = particles[right];
                p2 = particles[bottom];

                Sd = new HooksLaw.SpringDamper(p1, p2);
                springDampers.Add(Sd);
            }

            if (i < (colms * rows) - colms && i % colms < colms - 1)
            {
                int bottom      = i + (int)colms;
                int bottomright = bottom + 1;

                p1 = particles[i];
                p2 = particles[bottomright];

                Sd = new HooksLaw.SpringDamper(p1, p2);
                springDampers.Add(Sd);
            }
        }
    }