예제 #1
0
    // Update is called once per frame
    void Update()
    {
        RemoveShipsFromList();

        // Put the job before so it can process in parallel
        PositionUpdateJob positionJob = new PositionUpdateJob()
        {
            velocity  = velocities,
            deltaTime = Time.deltaTime
        };

        positionJobHandle = positionJob.Schedule(transformAccessArray);

        for (int i = 0; i < ships.Count; i++)
        {
            Boid ship = ships[i];

            ship.force = ship.Calculate();
            Vector3 newAcceleration = ship.force / ship.mass;

            float smoothRate = Mathf.Clamp(9.0f * Time.deltaTime, 0.15f, 0.4f) / 2.0f;
            ship.acceleration = Vector3.Lerp(ship.acceleration, newAcceleration, smoothRate);

            ship.velocity += ship.acceleration * Time.deltaTime;
            ship.velocity  = Vector3.ClampMagnitude(ship.velocity, ship.maxSpeed);

            Vector3 globalUp = new Vector3(0, 0.2f, 0);
            Vector3 accelUp  = ship.acceleration * 0.03f;
            Vector3 bankUp   = accelUp + globalUp;
            smoothRate = Time.deltaTime * 5.0f;
            Vector3 tempUp = ship.transform.up;
            if (!shipComp[i].captured)
            {
                tempUp = Vector3.Lerp(tempUp, bankUp, smoothRate);
            }

            if (ship.velocity.magnitude > float.Epsilon)
            {
                if (!shipComp[i].captured)
                {
                    ship.transform.LookAt(ship.transform.position + ship.velocity, tempUp);
                }
                ship.velocity *= 0.99f;
            }

            velocities[i] = ship.velocity;
        }

        audioSource.volume = videoManager.playingVideo ? 0.25f : 1.0f;
    }