Exemple #1
0
        // Update is called once per frame
        void Update()
        {
            if (bExitScene)
            {
                bExitScene = false;
                ExitScene();
            }

            if (state == State.SendTelemetry)
            {
                if (bResetCar)
                {
                    car.RestorePosRot();
                    pm.path.ResetActiveSpan();

                    if (carObj != null)
                    {
                        LapTimer t = carObj.transform.GetComponentInChildren <LapTimer>();

                        //reset last controls
                        car.RequestSteering(0.0f);
                        car.RequestThrottle(0.0f);
                        car.RequestFootBrake(10.0f);

                        if (t != null)
                        {
                            t.ResetRace();
                        }
                    }

                    bResetCar = false;
                }


                timeSinceLastCapture += Time.deltaTime;

                if (timeSinceLastCapture > 1.0f / limitFPS)
                {
                    timeSinceLastCapture -= (1.0f / limitFPS);
                    SendTelemetry();
                }

                if (ai_text != null)
                {
                    ai_text.text = string.Format("NN: {0} : {1}", ai_steering, ai_throttle);
                }
            }
        }
Exemple #2
0
        // Update is called once per frame
        void Update()
        {
            if (bExitScene)
            {
                bExitScene = false;
                ExitScene();
            }

            if (state == State.SendTelemetry)
            {
                if (bResetCar)
                {
                    car.RestorePosRot();
                    pm.path.ResetActiveSpan();

                    if (carObj != null)
                    {
                        LapTimer t = carObj.transform.GetComponentInChildren <LapTimer>();

                        //reset last controls
                        car.RequestSteering(0.0f);
                        car.RequestThrottle(0.0f);
                        car.RequestFootBrake(10.0f);

                        if (t != null)
                        {
                            t.ResetRace();
                        }

                        GameObject body = CarSpawner.getChildGameObject(carObj, "body");
                        if (body != null)
                        {
                            RaceCheckPoint[] checkPoints = GameObject.FindObjectsOfType <RaceCheckPoint>();
                            foreach (RaceCheckPoint cp in checkPoints)
                            {
                                if (cp.RemoveBody(body))
                                {
                                    Debug.Log("resetting checkpoint.");
                                }
                                else
                                {
                                    Debug.LogWarning("failed to reset checkpoint.");
                                }
                            }
                        }
                        else
                        {
                            Debug.LogWarning("failed to find car body.");
                        }
                    }

                    bResetCar = false;
                }


                timeSinceLastCapture += Time.deltaTime;

                if (timeSinceLastCapture > 1.0f / limitFPS)
                {
                    timeSinceLastCapture -= (1.0f / limitFPS);
                    SendTelemetry();
                }

                if (ai_text != null)
                {
                    ai_text.text = string.Format("NN: {0} : {1}", ai_steering, ai_throttle);
                }
            }
        }