예제 #1
0
    // Update is called once per frame
    protected virtual void Update()
    {
        if (steeringCalculate == null)
        {
//			print("trying");
            steeringCalculate = new SteeringCalculateWeightedSum();
        }


        // combined steering force from steering behavior
        Vector2 steeringForce = steeringCalculate.CalculateSteering(this);

        Vector2 acceleration = steeringForce / mass;         // acceleration = force / mass

        // update velocity
        velocity += acceleration * Time.deltaTime * TimeController.GameSpeed;

        // make sure it does not exceed maximum velocity ------------- ENABLE THIS LATER
        velocity = truncateSpeed(velocity);

        position += velocity * Time.deltaTime * TimeController.GameSpeed;         // update position

        // update the heading if we have a very small velocity
        if (velocity.magnitude > 0.00001)
        {
            heading    = velocity.normalized;
            tf.forward = new Vector3(heading.x, 0, heading.y);
//			side = heading.	 ------------ MIGHT NEED IMPLEMENT SIDE LATER
        }

        if (steering == null)
        {
//			print("trying");
            steering = new Steering(this, steeringCalculate);
        }


        //if (flee) { steering.Flee (targetVehicle); flee = false; } // TEMPORARY
        //if (pursuit) { steering.Pursuit (targetVehicle); flee = false; } // TEMPORARY
        //if (arrive) { steering.Arrive (new Vector2(targetVehicle.transform.position.x, targetVehicle.transform.position.z)); arrive = false; } // TEMPORARY

        // don't forget steering update
        steering.ManualUpdate();
    }