// Update is called once per frame void FixedUpdate() { // checks if the player is contacting the ground isOnGround = Physics2D.OverlapCircle(groundChecker.position, groundCheckerRadius, groundLayer); // checks if player's head has hit the ground if (Physics2D.OverlapCircle(headChecker.position, headCheckerRadius, groundLayer)) { gb.DestroyMe(); } // prevents character from move faster than the max speed; if (mRB.velocity.magnitude >= maxSpeed) { mRB.velocity = mRB.velocity.normalized * maxSpeed; } // player can only rotate when in the air if (!isOnGround && !isAboveRail) { mRB.MoveRotation(mRB.rotation - Input.GetAxis("Horizontal") * rotationSpeed * Time.fixedDeltaTime); // mRB.AddTorque(Input.GetAxis("Horizontal") * -rotationSpeed); different rotation method feels different } if (isAboveRail) { gb.UpdateScore(2); if (Input.GetAxis("Vertical") < 0) { mRB.AddForce(transform.right * grindSpeed); } } // apply speed boost for x amount of seconds if (boost) { speedBoostTime -= Time.deltaTime; if (speedBoostTime > 0) { ApplySpeedBoost(); } else { boost = false; speedMultiplier = 1; speedBoostTime = 2f; // reset timer } } // update text gb.UpdateSpeedMulText("Speed multiplier: " + speedMultiplier.ToString()); if (jumped) { CheckForTricks(); } }
// Use this for initialization void Start() { mRB = GetComponent <Rigidbody2D>(); gm = GameObject.Find("Game Manager"); gb = gm.GetComponent <GlobalBehavior>(); rayCastLeft = GameObject.Find("ray_cast_left").GetComponent <raycastUp>(); rayCastRight = GameObject.Find("ray_cast_right").GetComponent <raycastUp>(); speedMultiplier = 1; gb.UpdateLandingText("Landing: In Air"); gb.UpdateSpeedMulText("Speed multiplier: " + speedMultiplier.ToString()); gb.UpdateTrickText("Trick: "); }