public void Reset()
 {
     h = 0;
     v = 0;
     m_Car.Move(0, 0, 0, 0);
     m_Car.Reset();
     Fitness          = 0;
     distanceTraveled = 0;
     crashed          = false;
     m_Car.m_Rigidbody.isKinematic = false;
 }
    private void FixedUpdate()
    {
        // pass the input to the car!
        float h = Input.GetAxis("Oculus_CrossPlatform_SecondaryThumbstickHorizontal");
        float v = Input.GetAxis("Oculus_CrossPlatform_SecondaryThumbstickVertical");

#if !MOBILE_INPUT
        float handbrake = Input.GetAxis("Jump");
        m_Car.Move(h, v, v, handbrake);
#else
        m_Car.Move(h, v, v, 0f);
#endif
    }
    private void FixedUpdate()
    {
        // pass the input to the car!
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

#if !MOBILE_INPUT
        float handbrake = Input.GetAxis("Jump");
        m_Car.Move(h, v, v, handbrake);
#else
        m_Car.Move(h, v, v, 0f);
#endif
    }
    private void FixedUpdate()
    {
        if (toucpadControl)
        {
            v = GetThrottleInput();
            h = -GetSteeringInput();
        }

        if (isTesting)
        {
            h = Input.GetAxis("Horizontal");
            v = Input.GetAxis("Vertical");
        }

#if !MOBILE_INPUT
        //
        float handbrake = GetThrottleBreak();
        m_Car.Move(h, v, v, handbrake);
#else
        m_Car.Move(h, v, v, 0f);
#endif
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(0);
        }

        throttle = Input.GetAxis("Vertical");
        steer    = Input.GetAxis("Horizontal");
        brake    = Input.GetAxis("Jump");

        m_Car.Move(steer, throttle, throttle, brake);
    }
Exemple #6
0
    private void FixedUpdate()
    {
        var dir  = goal.position - m_Car.transform.position;
        var dirH = Vector3.Project(dir, m_Car.transform.right);

        var v = 0f;

        if (dir.magnitude > 5f)
        {
            v = 3;
        }
        var h = 0f;

        if (Vector3.Angle(dir, m_Car.transform.forward) < 15)
        {
            v = 3;
        }
        else
        {
            Debug.Log(dirH);
            if ((m_Car.transform.right + dirH.normalized / 2).magnitude > 1)
            {
                h = 3;
            }
            else
            {
                h = -3;
            }
            //h = -3;
        }

        var handbrake = 0f;

        //if(dir.magnitude < 2f)
        //{
        //    handbrake = 1;
        //}


        m_Car.Move(h, v, v, handbrake);
    }
    private void FixedUpdate()
    {
        charge();

        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        // ü·Â¹Ùs ÄÚµå
        if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
        {
            energe_bar_green.fillAmount -= m_minusHp / m_totalHp;
            energe_color();
        }


        // pass the input to the car!

        if ((box[0].transform.localPosition.x > -14) && (box[0].transform.localPosition.x < -8))
        {
            stage[0].SetActive(true);
        }
        if ((box[1].transform.localPosition.x > -14) && (box[1].transform.localPosition.x < -8))
        {
            stage[0].SetActive(true);
        }

        if ((box[4].transform.localPosition.x > -14) && (box[4].transform.localPosition.x < -8))
        {
            stage[1].SetActive(true);
        }
        if ((box[5].transform.localPosition.x > -14) && (box[5].transform.localPosition.x < -8))
        {
            stage[1].SetActive(true);
        }

        if ((box[8].transform.localPosition.x > -14) && (box[8].transform.localPosition.x < -8))
        {
            stage[2].SetActive(true);
        }
        if ((box[9].transform.localPosition.x > -14) && (box[9].transform.localPosition.x < -8))
        {
            stage[2].SetActive(true);
        }

        if ((box[10].transform.localPosition.x > -14) && (box[10].transform.localPosition.x < -8))
        {
            stage[3].SetActive(true);
        }
        if ((box[11].transform.localPosition.x > -14) && (box[11].transform.localPosition.x < -8))
        {
            stage[3].SetActive(true);
        }

        if ((box[12].transform.localPosition.x > -14) && (box[12].transform.localPosition.x < -8))
        {
            stage[4].SetActive(true);
        }
        if ((box[13].transform.localPosition.x > -14) && (box[13].transform.localPosition.x < -8))
        {
            stage[4].SetActive(true);
        }


        if (count < 6)
        {
            gameover.text         = "ROUND " + count.ToString();
            Timecount_player     += Time.deltaTime;
            Timelabel_player.text = string.Format("{0:N2}", "Player " + Timecount_player);
        }
        else
        {
            gameover.text            = "FINISH";
            Timelabel_player.enabled = false;
        }

#if !MOBILE_INPUT
        float handbrake = Input.GetAxis("Jump");
        m_Car.Move(h, v, v, handbrake);
#else
        m_Car.Move(h, v, v, 0f);
#endif
    }
Exemple #8
0
    private void FixedUpdate()
    {
        if (m_Target == null || !m_Driving)
        {
            // Car should not be moving,
            // use handbrake to stop
            m_CarController.Move(0, 0, -1f, 1f);
        }
        else
        {
            Vector3 fwd = transform.forward;
            if (m_Rigidbody.velocity.magnitude > m_CarController.MaxSpeed * 0.1f)
            {
                fwd = m_Rigidbody.velocity;
            }

            float desiredSpeed = m_CarController.MaxSpeed;

            // now it's time to decide if we should be slowing down...
            switch (m_BrakeCondition)
            {
            case BrakeCondition.TargetDirectionDifference:
            {
                // the car will brake according to the upcoming change in direction of the target. Useful for route-based AI, slowing for corners.

                // check out the angle of our target compared to the current direction of the car
                float approachingCornerAngle = Vector3.Angle(m_Target.forward, fwd);

                // also consider the current amount we're turning, multiplied up and then compared in the same way as an upcoming corner angle
                float spinningAngle = m_Rigidbody.angularVelocity.magnitude * m_CautiousAngularVelocityFactor;

                // if it's different to our current angle, we need to be cautious (i.e. slow down) a certain amount
                float cautiousnessRequired = Mathf.InverseLerp(0, m_CautiousMaxAngle,
                                                               Mathf.Max(spinningAngle,
                                                                         approachingCornerAngle));
                desiredSpeed = Mathf.Lerp(m_CarController.MaxSpeed, m_CarController.MaxSpeed * m_CautiousSpeedFactor,
                                          cautiousnessRequired);
                break;
            }

            case BrakeCondition.TargetDistance:
            {
                // the car will brake as it approaches its target, regardless of the target's direction. Useful if you want the car to
                // head for a stationary target and come to rest when it arrives there.

                // check out the distance to target
                Vector3 delta = m_Target.position - transform.position;
                float   distanceCautiousFactor = Mathf.InverseLerp(m_CautiousMaxDistance, 0, delta.magnitude);

                // also consider the current amount we're turning, multiplied up and then compared in the same way as an upcoming corner angle
                float spinningAngle = m_Rigidbody.angularVelocity.magnitude * m_CautiousAngularVelocityFactor;

                // if it's different to our current angle, we need to be cautious (i.e. slow down) a certain amount
                float cautiousnessRequired = Mathf.Max(
                    Mathf.InverseLerp(0, m_CautiousMaxAngle, spinningAngle), distanceCautiousFactor);
                desiredSpeed = Mathf.Lerp(m_CarController.MaxSpeed, m_CarController.MaxSpeed * m_CautiousSpeedFactor,
                                          cautiousnessRequired);
                break;
            }

            case BrakeCondition.NeverBrake:
                break;
            }

            // Evasive action due to collision with other cars:

            // our target position starts off as the 'real' target position
            Vector3 offsetTargetPos = m_Target.position;

            // if are we currently taking evasive action to prevent being stuck against another car:
            if (Time.time < m_AvoidOtherCarTime)
            {
                // slow down if necessary (if we were behind the other car when collision occured)
                desiredSpeed *= m_AvoidOtherCarSlowdown;

                // and veer towards the side of our path-to-target that is away from the other car
                offsetTargetPos += m_Target.right * m_AvoidPathOffset;
            }
            else
            {
                // no need for evasive action, we can just wander across the path-to-target in a random way,
                // which can help prevent AI from seeming too uniform and robotic in their driving
                offsetTargetPos += m_Target.right *
                                   (Mathf.PerlinNoise(Time.time * m_LateralWanderSpeed, m_RandomPerlin) * 2 - 1) *
                                   m_LateralWanderDistance;
            }

            // use different sensitivity depending on whether accelerating or braking:
            float accelBrakeSensitivity = (desiredSpeed < m_CarController.CurrentSpeed)
                                              ? m_BrakeSensitivity
                                              : m_AccelSensitivity;

            // decide the actual amount of accel/brake input to achieve desired speed.
            float accel = Mathf.Clamp((desiredSpeed - m_CarController.CurrentSpeed) * accelBrakeSensitivity, -1, 1);

            // add acceleration 'wander', which also prevents AI from seeming too uniform and robotic in their driving
            // i.e. increasing the accel wander amount can introduce jostling and bumps between AI cars in a race
            accel *= (1 - m_AccelWanderAmount) +
                     (Mathf.PerlinNoise(Time.time * m_AccelWanderSpeed, m_RandomPerlin) * m_AccelWanderAmount);

            // calculate the local-relative position of the target, to steer towards
            Vector3 localTarget = transform.InverseTransformPoint(offsetTargetPos);

            // work out the local angle towards the target
            float targetAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg;

            // get the amount of steering needed to aim the car towards the target
            float steer = Mathf.Clamp(targetAngle * m_SteerSensitivity, -1, 1) * Mathf.Sign(m_CarController.CurrentSpeed);

            // feed input to the car controller.
            m_CarController.Move(steer, accel, accel, 0f);

            // if appropriate, stop driving when we're close enough to the target.
            if (m_StopWhenTargetReached && localTarget.magnitude < m_ReachTargetThreshold)
            {
                m_Driving = false;
            }
        }
    }