Example #1
0
    void Start()
    {
        // create our neural networks for the genomes
        species       = new GeneticController(numGenomes, mutationRate);
        cars          = new GameObject[numSimulate];
        carController = new AICarController[numSimulate];
        bestCar       = carController[0];

        CarCheckPoint checkpoint = carFab.GetComponent <CarCheckPoint>();

        checkpoint.track = track;

        // Instantiate the number of cars we are going to simulate
        // Add assign them an AI Controller

        for (int i = 0; i < numSimulate; i++)
        {
            cars[i]                  = Instantiate(carFab, startingPos, carFab.transform.rotation);
            carController[i]         = cars[i].GetComponent <AICarController>();
            carController[i].network = species.population[i];
        }

        currentGenome = numSimulate;
        batchSimulate = numSimulate;

        Network_GUI = Instantiate(Network_GUI);
        UI_Genetics genetics = Network_GUI.GetComponentInChildren <UI_Genetics>();

        genetics.academy = this;
        networkUI        = Network_GUI.GetComponentInChildren <UI_Network>();
        networkUI.Display(carController[0].network);
    }
 void Start()
 {
     // Get the checkpoints
     carCheckPoint = car.GetComponent <CarCheckPoint>();
     playerStopped = false;
     playerHitWall = false;
     hitCheckPoint = false;
     startingPos   = car.position;
     carRotation   = car.rotation;
 }
 void Start()
 {
     // Get the checkpoints
     carCheckPoint   = gameObject.GetComponent <CarCheckPoint>();
     playerStopped   = false;
     playerHitWall   = false;
     hitCheckPoint   = false;
     startingPos     = gameObject.transform.position;
     carRotation     = gameObject.transform.rotation;
     timerStarted    = false;
     firstCheckpoint = carCheckPoint.nextCheckpoint;
 }
Example #4
0
    public override void activateSkill()
    {
        float     posRandom   = 3;
        float     angleRandom = 50;
        CarStatus attacker    = GetComponent <CarStatus>();
        int       myDist      = FindObjectOfType <RankingSystem>().GetCarDist(GetComponent <Car>());

        for (int i = 0; i < 10; ++i)
        {
            CarCheckPoint respawnPoint = findCheckPoint(myDist + i);
            if (respawnPoint == null)
            {
                return;
            }
            Vector3 spawnPos = new Vector3(
                respawnPoint.transform.position.x,
                respawnPoint.transform.position.y,
                respawnPoint.transform.position.z
                );
            Vector3    posCenter     = spawnPos + new Vector3(posRandom * Random.value - 0.5f * posRandom, 0, posRandom * Random.value - 0.5f * posRandom);
            Quaternion spawnRotation = Quaternion.Euler(new Vector3(angleRandom * Random.value - 0.5f * angleRandom, 0, angleRandom * Random.value - 0.5f * angleRandom));
            int        spearIdx      = Random.Range(0, spears.Length);
            weaponInstance = Instantiate(spears[spearIdx], posCenter, spawnRotation);
            weaponInstance.GetComponent <TrapWeapons>().attacker = attacker;

            Vector3 posLeft = spawnPos - respawnPoint.transform.right * 5f + new Vector3(posRandom * Random.value - 0.5f * posRandom, 0, posRandom * Random.value - 0.5f * posRandom);
            spawnRotation  = Quaternion.Euler(new Vector3(angleRandom * Random.value - 0.5f * angleRandom, 0, angleRandom * Random.value - 0.5f * angleRandom));
            spearIdx       = Random.Range(0, spears.Length);
            weaponInstance = Instantiate(spears[spearIdx], posLeft, spawnRotation);
            weaponInstance.GetComponent <TrapWeapons>().attacker = attacker;

            Vector3 posRight = spawnPos + respawnPoint.transform.right * 5f + new Vector3(posRandom * Random.value - 0.5f * posRandom, 0, posRandom * Random.value - 0.5f * posRandom);
            spawnRotation  = Quaternion.Euler(new Vector3(angleRandom * Random.value - 0.5f * angleRandom, 0, angleRandom * Random.value - 0.5f * angleRandom));
            spearIdx       = Random.Range(0, spears.Length);
            weaponInstance = Instantiate(spears[spearIdx], posRight, spawnRotation);
            weaponInstance.GetComponent <TrapWeapons>().attacker = attacker;

            isSkillUsing = true;
        }


        if (skillAudio == null)
        {
            return;
        }
        // play once
        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.clip   = skillAudio;
        source.volume = 1;
        source.loop   = false;
        source.Play();
    }
Example #5
0
    private void respawn()
    {
        CarCheckPoint respawnPoint = findCheckPoint(respawnPositionIdx);

        if (respawnPoint == null)
        {
            return;
        }
        Vector3 posCenter = new Vector3(
            respawnPoint.transform.position.x,
            respawnPoint.transform.position.y,
            respawnPoint.transform.position.z
            );
        Vector3 posLeft  = posCenter - respawnPoint.transform.right * 5f;
        Vector3 posRight = posCenter + respawnPoint.transform.right * 5f;
        Vector3 pos      = posCenter;

        foreach (Car car in FindObjectsOfType <Car>())
        {
            if ((car.transform.position - pos).magnitude < 2.5f)
            {
                pos = posLeft;
                foreach (Car car1 in FindObjectsOfType <Car>())
                {
                    if ((car1.transform.position - posLeft).magnitude < 2.5f)
                    {
                        pos = posRight;
                    }
                }
                break;
            }
        }
        Quaternion rot = respawnPoint.transform.rotation;

        transform.position = pos;
        transform.rotation = rot;
        reSpawnTimer       = 0;
    }