Esempio n. 1
0
    void controlSpeed()
    {
        Vector3 posRayUp = new Vector3(transform.position.x, transform.position.y, transform.position.z);
        //	Vector3 posRayUp = new Vector3(transform.position.x,transform.position.y);
        //	Vector3 directRay = new Vector3(1,0,0);
        RaycastHit2D hitUp = Physics2D.Raycast(posRayUp, transform.up);

//	Debug.Log ("Transform up: " + transform.up);
        float dev = getDeviation();

        if (transform.rotation.z > -0.23f)
        {
            //this.direction = 0;
            //	Debug.Log ("Dev roration: " + dev);
            //dev = 0.6f;
        }

        if (dev == 1)
        {
            return;
        }
        this.speed = Mathf.Abs(Speed.clarify(1, 0f, 10f, dev));

        int   obj    = 0;
        float disFob = 10;
        float df     = 0;

        if (hitUp)
        {
            if (hitUp.collider.gameObject.tag == "TrafficLight")
            {
                TrafficLightController traffic = (TrafficLightController)hitUp.collider.gameObject.GetComponent <TrafficLightController> ();
                float dis = hitUp.distance;
                //	Debug.Log ("Distance: "+dis);
                this.speed = Mathf.Abs(Speed.clarify(traffic.getIdL(), traffic.getRatioTime(), dis, dev));
                obj        = 0;
                //Debug.Log ("Distance: " + dis + " Time: " + traffic.getRatioTime() + " Deviation: " + dev);
                //	Debug.Log ("Speed Controll: " + this.speed);
            }
            else if (hitUp.collider.gameObject.tag == "ForbiddenCar" && hitUp.distance < 2f)
            {
                df     = hitUp.collider.gameObject.GetComponent <ForbiddenCar> ().getDeviation();
                disFob = hitUp.distance;
                //	this.speed = Mathf.Abs (Forbidden.clarify (hitUp.distance, df, 0));
                obj = 1;
                Debug.Log("ForbiddenCar Distance: " + hitUp.distance);
                //	Debug.Log ("ForbiddenCar Deviation: " + df);
            }
        }
        ;

        //Debug.Log ("Dev: " + dev);

        steer(dev, disFob, df, obj);
    }