Exemplo n.º 1
0
    // 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();
        }
    }
Exemplo n.º 2
0
 void LocalDestroy()
 {
     speedMultiplier = 0f;
     boost           = false;
     jumped          = false;
     tricksInARow    = 1;
     gb.DestroyMe();
 }