Ejemplo n.º 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();
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
 public SteeringPerson(MovingEntity me, SteeringCalculate sc)
     : base(me, sc)
 {
     // don't need anything here
 }
 public SteeringVehicle(MovingEntity me, SteeringCalculate sc) : base(me, sc)
 {
     // don't need anything here
 }
Ejemplo n.º 5
0
 public Steering(MovingEntity me, SteeringCalculate sc)
 {
     movingEntity = me;
     steeringCalculate = sc;
 }
Ejemplo n.º 6
0
 public Steering(MovingEntity me, SteeringCalculate sc)
 {
     movingEntity      = me;
     steeringCalculate = sc;
 }