Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float dt = Time.fixedDeltaTime;

        car.UpdateLocationAndVelocity(dt);

        double rpm = car.GetVx() * 60.0 * car.GetGearRatio() * car.FinalDriveRatio / (2.0 * Mathf.PI * car.WheelRadius);

        car.OmegaE = rpm;

        transform.position = new Vector3(transform.position.x, transform.position.y, (float)car.GetX());
    }
Example #2
0
        //  This method is called by the Timer every 0.05 seconds.
        public void ActionPerformed(object source, EventArgs e)
        {
            //테스트
            if (car.OmegaE > 7500)
            {
                car.ShiftGear(1);
            }
            if ((int)(car.GetVx() * 3.6) > 270)
            {
                //  stop the timer.
                gameTimer.Stop();

                //  Update the display.
                UpdateDisplay();
            }

            //  Figure out if the car is accelerating,
            //  cruising, or braking, and set the mode of
            //  the car accordingly
            if (accelButton.Checked == true)
            {
                car.Mode = "accelerating";
            }
            else if (cruiseButton.Checked == true)
            {
                car.Mode = "cruising";
            }
            else
            {
                car.Mode = "braking";
            }

            //  Update the car velocity and position at the next
            //  time increment.
            double timeIncrement = 0.06;

            car.UpdateLocationAndVelocity(timeIncrement);

            //  Compute the new engine rpm value
            double rpm = car.GetVx() * 60.0 * car.GetGearRatio() * car.FinalDriveRatio / (2.0 * Math.PI * car.WheelRadius);

            car.OmegaE = rpm;

            //  If the rpm exceeds the redline value, put a
            //  warning message on the screen. First, clear the
            //  message textfield of any existing messages.
            messageTextBox.Text = "";
            if (car.OmegaE > car.Redline)
            {
                messageTextBox.Text = "Warning: Exceeding redline rpm";
            }
            if (car.OmegaE > 8000.0)
            {
                messageTextBox.Text = "You have blown the engine!";
                gameTimer.Stop();
            }

            //  Update the location of the rectangular markers
            rectangleOneX = rectangleOneX + 10.0 * car.GetVx() * timeIncrement;
            rectangleTwoX = rectangleTwoX + 10.0 * car.GetVx() * timeIncrement;

            //  If the markers have gone off the display, move them
            //  back to zero
            if (rectangleOneX > 401.0)
            {
                rectangleOneX = 0.0;
            }
            if (rectangleTwoX > 401.0)
            {
                rectangleTwoX = 0.0;
            }

            //  Update the display
            UpdateDisplay();
        }
    //private bool isGnd = false;


    private void FixedUpdate()
    {
        //중력
        if (transform.position.y > 0.05)
        {
            vel += -9.81f * Time.fixedDeltaTime;
        }
        else
        {
            vel = 0f;
        }
        carRB.velocity = new Vector3(0f, vel, 0f);


        // //max rpm 도달 시간 출력
        // if (car.OmegaE <= 8000.0)
        // {
        //
        // }

        realtime += Time.fixedDeltaTime;


        //  Display the current time
        timeTextBox.text = "" + realtime;
        //timeTextBox.text = "" + (float)car.GetTime() * realtime;

        //  Convert the velocity from m/s to km/hr and
        //  only show integer values
        velocityTextBox.text = "" + (int)(car.GetVx() * 3.6);      //시간과 관련

        if ((int)(car.GetVx() * 3.6) < 271)
        {
            maxSpeedTime.text = realtime + "";
        }

        this.transform.Translate(new Vector3(0f, 0f, (float)(car.GetVx() * 3.6 * (float)timeIncrement)));   //거리=속도*시간
        //Debug.Log((float)(car.GetVx() * 3.6 * (float)timeIncrement));

        //  Only show integer values for rpm, gear number,
        //  and distance.
        rpmTextBox.text      = "" + (int)car.OmegaE;
        gearTextBox.text     = "" + (int)car.GearNumber;
        distanceTextBox.text = "" + (int)car.GetX();


        car.Mode = "accelerating";  //임시
        if (Input.GetKey(KeyCode.W))
        {
            car.Mode = "accelerating";
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            car.Mode = "braking";
        }
        else
        {
            car.Mode = "accelerating";  //임시
            //car.Mode = "cruising";
        }

        if (Input.GetKeyDown(KeyCode.E) || car.OmegaE > 7500)   //테스트
        {
            car.ShiftGear(1);
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            car.ShiftGear(-1);
        }

        //  Update the car velocity and position at the next
        //  time increment.
        timeIncrement = 0.06 * tempDiv;  //시간과 관련
        car.UpdateLocationAndVelocity(timeIncrement);

        //  Compute the new engine rpm value
        double rpm = car.GetVx() * 60.0 * car.GetGearRatio()
                     * car.FinalDriveRatio / (2.0 * Math.PI * car.WheelRadius); //시간과 관련

        car.OmegaE = rpm;

        // rpm이 redline을 넘어서면 Warning
        // rpm이 8000을 넘어서면 엔진 정지
        messageTextBox.text = "";
        if (car.OmegaE > car.Redline)
        {
            messageTextBox.text = "Warning: Exceeding redline rpm";
        }
        if (car.OmegaE > 8000.0)
        {
            messageTextBox.text = "You have blown the engine!";
            //gameTimer.Stop();
        }
    }