예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        car_variant = GameObject.FindGameObjectWithTag("Player");
        text        = GameObject.Find("LapTimeText");
        s_text      = GameObject.Find("SpeedText");
        finish      = GameObject.Find("FinalText");

        car_body = car_variant.GetComponent <Rigidbody>();

        finish.SetActive(false);

        lap_time_text = text.GetComponent <Text>();
        speed_text    = s_text.GetComponent <Text>();

        check_point_check = car_variant.GetComponent <CheckpointCheck>();
        car_controller    = car_variant.GetComponent <UnityStandardAssets.Vehicles.Car.CarController>();
        car_user_control  = car_variant.GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl>();

        current_speed   = car_controller.CurrentSpeed;
        speed_text.text = current_speed.ToString();

        lap_time           = check_point_check.lap_time;
        lap_time_text.text = "LAP TIME: ";

        victory = check_point_check.victory;
    }
예제 #2
0
    private void OnSceneChanged(Scene scene, LoadSceneMode mode)
    {
        m_carControl = FindObjectOfType <UnityStandardAssets.Vehicles.Car.CarUserControl> ();
        m_waypoints  = FindObjectsOfType <Waypoint> ().ToList();
        m_raycaster  = m_carControl.GetComponent <Eyes> ();

        StartCoroutine(WaitGenomeStart());
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        DrivingLogic     = GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl>();
        fuel             = 100f;
        nitrous          = 100f;

        rb               = GetComponent <Rigidbody>();
        Exhaust          = transform.FindChild("Exhaust").GetComponent <ParticleSystem>();
        rb.centerOfMass += Vector3.down * 10;
    }
예제 #4
0
    private void ChangeScene()
    {
        ChangeSubject();
        m_canGo      = false;
        m_carControl = null;
        m_raycaster  = null;
        m_waypoints.Clear();

        string currentSceneName = SceneManager.GetActiveScene().name;

        SceneManager.LoadSceneAsync(currentSceneName, LoadSceneMode.Single);
    }
예제 #5
0
    //Slows the car down to a stop and stops the player from being able to move the car anymore. When this finishes
    //get out is called. Get out is called from the m_CarSlowDown script.
    public void slowDown()
    {
        UnityStandardAssets.Vehicles.Car.CarUserControl carUserControl = m_Car.GetComponentInChildren <UnityStandardAssets.Vehicles.Car.CarUserControl>();
        carUserControl.carOn = false;

        m_Car.GetComponentInChildren <UnityStandardAssets.Vehicles.Car.CarController>().enabled = false;

        CarSlowDown carSlowDown = m_Car.GetComponentInChildren <CarSlowDown>();

        carSlowDown.enabled       = true;
        carSlowDown.m_GameManager = this;
    }
예제 #6
0
    private void Start()
    {
        m_carControl = FindObjectOfType <UnityStandardAssets.Vehicles.Car.CarUserControl> ();
        m_waypoints  = FindObjectsOfType <Waypoint> ().ToList();
        m_raycaster  = m_carControl.GetComponent <Eyes> ();

        SceneManager.sceneLoaded += OnSceneChanged;

        if (m_geneticAlg == null)
        {
            m_geneticAlg = new GeneticAlgorithm();

            int totalWeights = 0;
            for (int i = 0; i < m_neuralTopology.Length - 1; i++)
            {
                totalWeights += m_neuralTopology [i] * m_neuralTopology [i + 1];
            }
            m_geneticAlg.GeneratePopulation(m_populationCount, totalWeights);

            m_neuralNet = new NeuralNetwork();
            if (loadBestGenome == false)
            {
                GeneticAlgorithm.Genome genome = m_geneticAlg.GetNextGenome();
                m_currentGenomeIndex = m_geneticAlg.GetCurrentGenomeIndex();
                m_neuralNet.CreateNetFromGenome(genome, m_neuralTopology);
            }
            else
            {
                BestAIRun bestRun = SaveLoad.LoadRun();
                GeneticAlgorithm.Genome genome = bestRun.genomeToSave;
                if (genome.weights.Count == 0)
                {
                    Debug.LogError("There are nothing to load. Uncheck 'Load Best Genome' option.");
                    Debug.Break();
                    return;
                }
                m_neuralNet.CreateNetFromGenome(genome, m_neuralTopology);

                m_currentGenerationIndex = bestRun.generationNumber;
                m_currentGenomeIndex     = bestRun.genomeNumber;
                m_bestFitness            = (int)genome.fitness;
            }

            m_defaultPosition = transform.position;
            m_defaultRotation = transform.rotation;
        }

        StartCoroutine(WaitGenomeStart());
    }
예제 #7
0
        // Use this for initialization
        private void Start()
        {
            m_WheelMeshLocalRotations = new Quaternion[4];
            for (int i = 0; i < 4; i++)
            {
                m_WheelMeshLocalRotations[i] = m_WheelMeshes[i].transform.localRotation;
            }
            m_WheelColliders[0].attachedRigidbody.centerOfMass = m_CentreOfMassOffset;

            m_MaxHandbrakeTorque = float.MaxValue;
            m_Rigidbody          = GetComponent <Rigidbody>();

            m_carUserControl = GetComponent <CarUserControl>();
            m_CurrentTorque  = m_FullTorqueOverAllWheels - (m_TractionControl * m_FullTorqueOverAllWheels);
        }
예제 #8
0
    public void SpawnVehicles(int vehicle)
    {
        GameObject newVehicle;

        gameTime   = readyTime;
        readyTimer = true;
        countDown  = true;
        spawnPoints[0].SetActive(false);
        newVehicle = Instantiate(playableVehicles.vehicles[raceData.vehicleNumber], spawnPoints[0].transform.position, spawnPoints[0].transform.rotation) as GameObject;
        newVehicle.transform.rotation = spawnPoints[0].transform.rotation;
        newVehicle.GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl>().enabled = false;
        racerInfo [0].racer              = newVehicle;
        racerInfo[0].racer.name          = racerInfo[0].racerName;
        racerInfo [0].lap                = 1;
        playerController                 = newVehicle.GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl>();
        racerInfo[0].aIHelper            = racerInfo[0].racer.GetComponent <RG_AIHelper>();
        racerInfo[0].aIController        = racerInfo[0].racer.GetComponent <UnityStandardAssets.Vehicles.Car.CarAIControl>();
        racerInfo [0].waypointController = racerInfo [0].racer.GetComponent <UnityStandardAssets.Utility.WaypointProgressTracker> ();
        racerInfo [0].currentWaypoint    = Waypoints [0];
        Debug.Log(raceData.numberOfRacers[raceData.raceNumber]);
        for (int i = 1; i < raceData.numberOfRacers[raceData.raceNumber]; i++)
        {
            spawnPoints[i].SetActive(false);
            newVehicle = Instantiate(opponentVehicles.vehicles[i - 1], spawnPoints[i].transform.position, spawnPoints[i].transform.rotation) as GameObject;
            newVehicle.transform.rotation = spawnPoints[i].transform.rotation;
            racerInfo[i].racer            = newVehicle;
            racerInfo[i].racerName        = opponentVehicles.opponentNames[i - 1];
            racerInfo[i].racer.name       = racerInfo[i].racerName;
            racerInfo [0].lap             = 1;
            if (racerInfo[i].racer.GetComponent <UnityStandardAssets.Utility.WaypointProgressTracker>())
            {
                racerInfo[i].aIHelper = racerInfo[i].racer.GetComponent <RG_AIHelper>();
                racerInfo[i].aIHelper.opponentNumber = i;
                racerInfo[i].aIController            = racerInfo[i].racer.GetComponent <UnityStandardAssets.Vehicles.Car.CarAIControl>();
                racerInfo [i].waypointController     = racerInfo [i].racer.GetComponent <UnityStandardAssets.Utility.WaypointProgressTracker> ();
                racerInfo [i].positionScore          = 0;
                racerInfo [i].currentWaypoint        = Waypoints [0];
            }
        }
        newVehicle = null;
        for (int i = 0; i < spawnPoints.Length; i++)
        {
            spawnPoints [i].SetActive(false);
        }
    }
예제 #9
0
파일: brake.cs 프로젝트: abd1121/FYP
 public void SetPlayer(GameObject player)
 {
     car           = player.GetComponent <CarUserControl>();
     carController = player.GetComponent <CarController>();
 }
예제 #10
0
        void Awake()
        {
            Instance = this;

            #if UNITY_STANDALONE || UNITY_EDITOR

            #elif !UNITY_STANDALONE || !UNITY_EDITOR
            ChangeInput();
            #endif
            ChangeInput();
        }
 private void Start()
 {
     carControl = GameObject.FindGameObjectWithTag("Player").GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl>();
 }
예제 #12
0
 private void Start()
 {
     m_carControl = GetComponent <UnityStandardAssets.Vehicles.Car.CarUserControl> ();
     m_brains     = FindObjectOfType <Brains> ();
 }
예제 #13
0
 // Use this for initialization
 void Start()
 {
     startTime = Time.time;
     car       = GetComponent <CarUserControl>();
 }