Exemplo n.º 1
0
    void Update()
    {
        bool isTouchingGround = CarManager.CheckGround(3f);

        if (isTouchingGroundLastFrame != isTouchingGround)
        {
            if (isTouchingGround)
            {
                if (CarManager.Flips >= 1)
                {
                    CarManager.Boost();
                }

                //Choose to rotate (30% Chance)
                Rotate = Random.Range(0, 3) == 0;

                //Choose lane (50% Chance)
                int rand = Random.Range(0, 2);

                if (rand == 0)
                {
                    DesiredX = -6.5f;
                }
                else
                {
                    DesiredX = 6.5f;
                }
            }
        }

        if (isTouchingGround)
        {
            CarManager.MoveSideways(DesiredX, LaneSwitchSpeed);
            CarManager.MoveForward();
        }
        else
        {
            if (Rotate)
            {
                CarManager.Rotate();
            }
        }

        isTouchingGroundLastFrame = isTouchingGround;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        bool isTouchingGround = CarManager.CheckGround(2.5f);

        if (isTouchingGround)
        {
            TimeSinceLanded += Time.deltaTime;
        }
        else
        {
            TimeSinceLanded = 0f;
        }

        if (Input)
        {
            Joystick.Update();

            float mag       = Joystick.GetMagnitude() / 20f;
            float roadWidth = LevelGenerator.instance.RoadWidth / 2f;

            CarManager.MoveSideways(PlayerPos.x + mag);

            if (isTouchingGround)
            {
                CarManager.Torque = 0f;

                if (CarManager.Flips > 0 && TimeSinceLanded < 1.5f)
                {
                    StartCoroutine(BoostPlayer());
                }

                CarManager.Flips = 0;
                CarManager.MoveForward();
            }
            else
            {
                CarManager.Rotate();
            }
        }
    }