Esempio n. 1
0
 //called when ther is a Collision with the car hitbox
 //gets - collisioninfo - the Collision information
 void OnCollisionEnter(Collision collisioninfo)
 {
     //checks if the Collision accured with a Barrier
     if (collisioninfo.collider.tag == "Barrier")
     {
         //print and log the collision basic info
         //Debug.Log("Crash in:" + collisioninfo.collider.name);
         //disable the car
         //movement.enabled = false;
         //restart spot
         //movement.transform.position = new Vector3((float)-178.59, (float)2.6, (float)162.12);
         //movement.transform.eulerAngles = new Vector3((float)0, (float)0, (float)0);
         //restart game
         if (!collisioninfo.collider.name.Equals("Barrier (11)") && !collisioninfo.collider.name.Equals("Barrier (27)"))
         {
             check.SetWeightSetIndex(check.GetWeightSetIndex() + 1);
             Debug.Log("index: " + check.GetWeightSetIndex().ToString());
             if (check.GetWeightSetIndex() <= 49)
             {
                 SceneManager.LoadScene("SandBox");
             }
             else
             {
                 WriteNewThoughtsToNextGen("TempData.bin", "Weights.bin", 1, 3);
                 check.enabled = false;
             }
         }
         else if (collisioninfo.collider.name.Equals("Barrier (158)"))
         {
             check.SetNextMove("left");
         }
         /////////////////////////////////
         //else if (collisioninfo.collider.name.Equals("Barrier (11)"))
         //{
         //    check.SetNextMove("right_10");
         //}
         //else
         //{
         //    check.SetNextMove("right_7");
         //}
         //////////////////////////////////
         //else if(collisioninfo.collider.name.Equals("Barrier (11)"))
         //{
         //    check.SetNextMove("right_10");
         //}
         else
         {
             check.SetNextMove("right_10");
         }
     }
 }
Esempio n. 2
0
    // Update is called once per frame - FIxedUpdate because we use Physics
    void FixedUpdate()
    {
        //transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, transform.eulerAngles.z);
        this.distance = (double)this.range;//the distance that the sensor
        lr.SetPosition(0, transform.position);
        RaycastHit hit;

        //checks if go hit
        this.distance = (double)this.range;
        if (Physics.Raycast(transform.position, transform.forward, out hit, range) && hit.collider)
        {
            lr.SetPosition(1, hit.point);// checnge the ray length
            if (hit.transform.tag == "Barrier")
            {
                this.distance = Vector3.Distance(transform.position, hit.point);//set the return value for the sensor
                if (this.distance > this.range)
                {
                    this.distance = (double)this.range;
                }
                if (transform.name.Equals("LaserPoint_3"))
                {
                    if ((hit.transform.name.Equals("Barrier (158)") || (hit.transform.name.Equals("Barrier (166)"))) && this.distance < 15)
                    {
                        check.SetNextMove("left");
                    }
                    else if (hit.transform.name.Equals("Barrier (210)") && this.distance < 27)
                    {
                        check.SetNextMove("weit");
                    }
                    //else if (((hit.transform.name.Equals("Barrier (166)")) || (hit.transform.name.Equals("Barrier (167)"))) && this.distance < 15)
                    //    check.SetNextMove("left_166");
                }
                else if (check.GetCountMove() == 0 && transform.name.Equals("LaserPoint_4") && Array.IndexOf(checkSens4Wall, hit.transform.name) > -1 && this.distance < 2.7)//2.7
                {
                    check.SetNextMove("Sleft");
                }
                //else
                //  this.distance = (double)this.range;
            }
        }
        else
        {
            lr.SetPosition(1, transform.forward * range);// set the ray length
        }
        //Debug.Log(transform.name + ": " + distance);//print the sensor return value
    }