예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale > 0f)
        {
            // Get center of flock
            float totalX = 0f;
            float totalY = 0f;
            float totalZ = 0f;
            float count  = 0;
            timer.Start();

            birds.UpdatePositions(); // Tree positions must be updated
            for (int i = 0; i < SceneController.flockSize; ++i)
            {
                // Profiler.BeginSample("State Vector Loop");
                Boid    bird     = birds[i];
                Vector3 position = bird.position;
                totalX += position.x;
                totalY += position.y;
                totalZ += position.z;
                count++;

                bird.Sense(birds);
                bird.Think();
                bird.Act(transform.GetChild(i));

                // Profiler.EndSample();
            }

            timer.Stop();
            times.Add(timer.ElapsedMilliseconds);
            timer.Reset();

            float centerX = totalX / count;
            float centerY = totalY / count;
            float centerZ = totalZ / count;

            flockCenter = new Vector3(centerX, centerY, centerZ);

            sphere.position = goal;

            if (Input.GetKey(KeyCode.Tab))
            {
                goal = new Vector3(Random.Range(-100.0f, 100.0f), Random.Range(10.0f, 70.0f), Random.Range(-100.0f, 100.0f));
            }
        }
    }