Exemple #1
0
    void Update()
    {
        // read the input from the controller, and send it straight to the kart controller
        kart.Thrust   = Input.GetAxis("Vertical");
        kart.Steering = Input.GetAxis("Horizontal");


        // debug controls for triggering various things
        if (Input.GetKeyDown(KeyCode.S))
        {
            kart.Spin(2.0f);
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            kart.Wiggle(2.0f);
        }

        if (Input.GetKeyDown(KeyCode.J))
        {
            kart.Jump(1.0f);
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            kart.SpeedBoost();
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            kart.SpeedPenalty();
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(kart.physicsBody.velocity.sqrMagnitude);
        Debug.Log("Kart " + playerNumber + ": " + checkPointCounter);


        if ((kart.IsGrounded) && ((gamepad.GetTriggerDown_R() || gamepad.GetTriggerDown_L())))
        {
            smoke1.Play();
            smoke2.Play();
        }
        else if (!gamepad.GetTriggerDown_R() || !gamepad.GetTriggerDown_L())
        {
            smoke1.Stop();
            smoke2.Stop();
        }

        if (!gamepad.GetTriggerDown_L() && !gamepad.GetTriggerDown_R())
        {
            if (!idleEngine.isPlaying)
            {
                idleEngine.Play();
            }
        }
        if (gamepad.GetTriggerDown_L() || gamepad.GetTriggerDown_R())
        {
            //     if(!engineAccelerate.isPlaying)
            //     {
            //       engineAccelerate.Play();
            //   }
        }

        if (kart.physicsBody.velocity.sqrMagnitude > 800)
        {
            if (idleEngine.isPlaying)
            {
                idleEngine.Stop();
            }

            if (!topEngineSpeed.isPlaying)
            {
                topEngineSpeed.Play();
            }
        }
        Debug.Log(kart.physicsBody.velocity.sqrMagnitude);



        if (gamepad.GetButtonDown("Y"))
        {
            lapNumber++;
        }

        if (lapManager == null)
        {
            lapManager = GameObject.Find("Manager").GetComponent <LapsManager>();
        }

        kartBody = kart.physicsBody;
        //If counter = 0 finish line = last checkpoint and first checkpoint = next.
        //if (checkPointCounter == 0)
        //{
        if (lapManager != null)
        {
            if (checkPointCounter == 0)
            {
                if (lapManager.checkPoints != null)
                {
                    nextCheckPoint = lapManager.checkPoints[0];
                }
                if (lapManager.FinishLine != null)
                {
                    lastCheckPoint = lapManager.FinishLine;
                }
            }
        }


        if (raceCountdownTimer < 0)
        {
            if (gamepad.GetButtonDown("Start") && !isPaused && !npcManager.isPaused)
            {
                npcManager.isPaused = true;
                isPaused            = true;
                Time.timeScale      = 0;
            }
            else if (gamepad.GetButtonDown("Start") && isPaused)
            {
                isPaused            = false;
                npcManager.isPaused = false;
                Time.timeScale      = 1;
            }
        }
        if (isPaused)
        {
            coolDown -= Time.unscaledDeltaTime;
            if (buttonIndex == 1)
            {
                if (gamepad.GetStick_L().Y < -deadZone && coolDown < 0)
                {
                    coolDown    = cdCopy;
                    buttonIndex = 2;
                }
                if (gamepad.GetButtonDown("A"))
                {
                    isPaused            = false;
                    npcManager.isPaused = false;
                    Time.timeScale      = 1;
                    npcManager.enabled  = false;
                }
                if (gamepad.GetButtonUp("A"))
                {
                    npcManager.enabled = false;
                }
            }

            if (buttonIndex == 2)
            {
                if (gamepad.GetStick_L().Y > deadZone && coolDown < 0)
                {
                    coolDown    = cdCopy;
                    buttonIndex = 1;
                }
                if (gamepad.GetButtonDown("A"))
                {
                    Time.timeScale = 1;
                    Destroy(GameObject.Find("Manager"));
                    SceneManager.LoadScene(0);
                }
            }
            greyBackDrop.enabled  = true;
            pauseContinue.enabled = true;
            pauseMenu.enabled     = true;
            pauseUI.enabled       = true;
        }
        else if (!isPaused)
        {
            greyBackDrop.enabled  = false;
            pauseContinue.enabled = false;
            pauseMenu.enabled     = false;
            pauseUI.enabled       = false;
        }

        if (buttonIndex == 1)
        {
            pauseContinue.color = Color.yellow;
            pauseMenu.color     = Color.grey;
        }
        if (buttonIndex == 2)
        {
            pauseContinue.color = Color.grey;
            pauseMenu.color     = Color.yellow;
        }

        //if (lapManager.endTime < 0 && lapNumber < 3)
        //{
        //    finalPosition = kartPosition;
        //}
        //If kart hits slick spin kart for set time.

        if (boostPlayer)
        {
            kart.SpeedBoost(boostPower, boostTime, 3.0f, 1.0f);
            if (!gasLeak.isPlaying)
            {
                gasLeak.Play();
            }
            boostPlayer = false;
        }



        if (hitSlick)
        {
            kart.Spin(slickSpinOutTime);
            kart.SpeedPenalty(slickSpeedPenalty, lockSteerTime, 1.0f);
            lockSteer = true;
            hitSlick  = false;
        }
        if (lockSteer)
        {
            lockSteerTime     -= Time.deltaTime;
            kart.maxSteerAngle = 0.0f;
            if (lockSteerTime < 0)
            {
                kart.maxSteerAngle = steerAngleCopy;
                lockSteerTime      = slickSpinOutTime;
                lockSteer          = false;
            }
        }
        raceCountdownTimer -= Time.deltaTime;
        if (raceCountdownTimer > 0)
        {
            kartBody.constraints = RigidbodyConstraints.FreezeAll;
        }
        else
        {
            kartBody.constraints = RigidbodyConstraints.None;
        }
        //If the player is disabled.
        if (playerDisabled)
        {
            Vector3 tempVector;
            deathParticles.Play();
            tempVector = deathParticles.transform.position;
            //Freeze rigidbody, disable mesh, reset velocity, move kart slightly back and up.
            if (!explosion.isPlaying)
            {
                explosion.Play();
            }

            disabledTimer       += Time.deltaTime;
            kartBody.velocity    = new Vector3();
            kartMat.material     = transparent;
            kartBody.constraints = RigidbodyConstraints.FreezeAll;
            mesh.SetActive(false);

            if (setOnce)
            {
                this.gameObject.transform.position = gameObject.transform.position + (transform.forward * 12);
                gameObject.transform.position      = gameObject.transform.position + (transform.up * 2);
                setOnce = false;
            }

            deathParticles.transform.position = tempVector;

            //If disable timer is greater than 0 take constraints off car
            //turn mesh on and turn off/on relevant bools.
            if (disabledTimer > 2.0f)
            {
                immuneToDamage = true;
                deathParticles.transform.position = kart.transform.position;
                deathParticles.Stop();
                respawnParticles.Play();
                kartBody.constraints = RigidbodyConstraints.None;
                disabledTimer        = 0.0f;
                playerDisabled       = false;

                mesh.SetActive(true);
                setOnce = true;
            }
        }

        if (immuneToDamage)
        {
            immuneTimer   -= Time.deltaTime;
            flashingTimer -= Time.deltaTime;


            if (flashingTimer < 0)
            {
                flashingTimer = ftCopy;

                if (flashFull)
                {
                    kartMat.material = matCopy;
                    wheel1.material  = wheelCopy;
                    wheel2.material  = wheelCopy;
                    wheel3.material  = wheelCopy;
                    wheel4.material  = wheelCopy;
                    flashClear       = true;
                    flashFull        = false;
                }
                else if (flashClear)
                {
                    kartMat.material       = transparent;
                    kartMat.material.color = Color.cyan;
                    wheel1.material        = transparent;
                    wheel1.material.color  = Color.cyan;
                    wheel2.material        = transparent;
                    wheel2.material.color  = Color.cyan;
                    wheel3.material        = transparent;
                    wheel3.material.color  = Color.cyan;
                    wheel4.material        = transparent;
                    wheel4.material.color  = Color.cyan;
                    flashClear             = false;
                    flashFull = true;
                }
            }


            if (immuneTimer < 0)
            {
                respawnParticles.Stop();
                immuneToDamage   = false;
                immuneTimer      = 5.0f;
                kartMat.material = matCopy;
                wheel1.material  = wheelCopy;
                wheel2.material  = wheelCopy;
                wheel3.material  = wheelCopy;
                wheel4.material  = wheelCopy;
            }
        }



        //If trigger down go forward else if left trigger is down
        //bring thrust back to 0.
        if (gamepad.GetTriggerDown_R() && !lockSteer)
        {
            kart.Thrust = gamepad.GetTrigger_R();
        }
        else if (!gamepad.GetTriggerDown_L())
        {
            kart.Thrust = 0;
        }

        //If trigger down go backward else if right trigger isnt down
        //bring thrust back to 0.
        if (gamepad.GetTriggerDown_L() && !lockSteer)
        {
            kart.Thrust = -gamepad.GetTrigger_L();
        }
        else if (!gamepad.GetTriggerDown_R())
        {
            kart.Thrust = 0.0f;
        }

        //Steering left stick X axis input.
        kart.Steering = gamepad.GetStick_L().X;


        if (kart.IsOverturned)
        {
            overTurnCounter -= Time.deltaTime;

            if (overTurnCounter < 0)
            {
                this.transform.forward  = lastCheckPoint.transform.forward;
                this.transform.position = lastCheckPoint.transform.position;
                playerDisabled          = true;
                overTurnCounter         = 3;
            }
        }

        //If b button traction, deceleration and breakpower
        // = set values else reset to defaults.
        if (gamepad.GetButton("B"))
        {
            if (kart.physicsBody.velocity.sqrMagnitude > 50.0f && kart.IsGrounded)
            {
                kart.steerSpeed = 0.4f;

                kart.decelerationSpeed = driftDeceleration;
                kart.breakPower        = breakPower;
                if (kart.physicsBody.velocity.sqrMagnitude < 200)
                {
                    kart.traction = 0.4f;
                }
                else if (kart.physicsBody.velocity.sqrMagnitude > 200)
                {
                    kart.traction = driftTraction;
                }
            }
        }
        else
        {
            kart.decelerationSpeed = kart.decelerationSpeedCopy;
            kart.breakPower        = 0.0f;
            kart.traction          = 0.4f;
            kart.steerSpeed        = steerSpeedCopy;
        }

        if (gamepad.GetButton("Back"))
        {
            this.transform.forward  = lastCheckPoint.transform.forward;
            this.transform.position = lastCheckPoint.transform.position; this.transform.forward = lastCheckPoint.transform.forward;
            this.transform.position = lastCheckPoint.transform.position;
        }

        Debug.Log(checkPointCounter);
    }
 protected override void OnPickupCollected(KartController kart)
 {
     kart.SpeedPenalty();
     kart.Spin(2.0f);
 }
 protected override void OnPickupCollected(KartController kart)
 {
     kart.SpeedPenalty(0.25f, 1.0f, 1.0f);
     kart.Wiggle(1.0f);
 }