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

        particle.AddForce(new Vector3(9.807f, 0, 0));
    }
示例#2
0
    void Update()
    {
        foreach (var p in particles)
        {
            if (p.gravity == true)
            {
                p.Update(Time.deltaTime);
                for (int i = 0; i < particles.Count - (int)colms; i++)
                {
                    particles[0].anchor = true;

                    p1 = particles[i];
                    p2 = particles[i + 1];
                    p3 = particles[i + (int)colms];

                    p1.position = objects[i].transform.position;
                    p2.position = objects[i + 1].transform.position;
                    p3.position = objects[i + (int)colms].transform.position;

                    p1.anchor = false;
                    p2.anchor = true;
                    p3.anchor = false;

                    CalculateWind(wind);
                }
            }
        }

        foreach (var s in springDampers)
        {
            s.CalculateForce(spring, rest, damping);
        }

        Wind_x.minValue = -10;
        Wind_x.maxValue = 10;
        wind.x          = Wind_x.value;

        Wind_y.minValue = -10;
        Wind_y.maxValue = 10;
        wind.y          = Wind_y.value;

        Wind_z.minValue = -10;
        Wind_z.maxValue = 10;
        wind.z          = Wind_z.value;
    }
示例#3
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);
            }
        }
    }