Ejemplo n.º 1
0
    public void Move(float move, bool crouch, bool jump, bool run)
    {
        // If crouching, check to see if the character can stand up

        /*if (!crouch && m_Anim.GetBool("Crouch"))
         * {
         *  // If the character has a ceiling preventing them from standing up, keep them crouching
         *  if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
         *  {
         *      crouch = true;
         *  }
         * }*/

        m_Running = (run && m_Grounded && Mathf.Abs(move) > 0.85f) || (m_RunLock && Mathf.Abs(move) > 0.85f);

        // Set whether or not the character is crouching in the animator
        //m_Anim.SetBool("Crouch", crouch);

        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // Reduce the speed if crouching by the crouchSpeed multiplier
            move = (crouch ? move * m_CrouchSpeed : move);

            // The Speed animator parameter is set to the absolute value of the horizontal input.

            // If the input is moving the player right and the player is facing left...
            if (move > 0 && !m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move < 0 && m_FacingRight)
            {
                // ... flip the player.
                Flip();
            }

            // Move the character
            m_TrueSpeed = (m_Running ? m_MaxSpeed * 1.5f : m_MaxSpeed);

            float m_yVelocity = m_Grounded && !m_OnLadder ? 0.0f: m_Rigidbody2D.velocity.y;

            /*m_Rigidbody2D.velocity = m_Grounded && -normal.x <= 0 ? new Vector2(move * m_TrueSpeed * normal.y, m_yVelocity + (move * m_TrueSpeed * -normal.x))
             *  : new Vector2(move * m_TrueSpeed, m_yVelocity);*/
            if (m_Grounded && ((-normal.x * move) < 0))
            {
                m_Rigidbody2D.velocity = new Vector2((move * normal.y) * m_TrueSpeed, ((move * -normal.x) * m_TrueSpeed) + m_yVelocity);
            }
            else
            {
                m_Rigidbody2D.velocity = new Vector2(move * m_TrueSpeed, m_yVelocity);
            }
            //m_Rigidbody2D.velocity = new Vector2((move * normal.y) * m_TrueSpeed, ((move * -normal.x) * m_TrueSpeed) + m_yVelocity);


            m_Anim.SetFloat("Speed", Mathf.Abs(m_Rigidbody2D.velocity.x), .3f, Time.deltaTime);

            //Tells the player object if it's moving or not
            //I've decided to only allow the player to be considered moving under their own will if they are grounded, in case something else decides to move the player while they're in the air. Essentially, stamina will only be added while on the ground.
            //There are tentative plans to move this system to a local velocity based system by calculating valocity without taking into account other
            playerStatistics.moving(move != 0 && (m_Grounded || ableToMove));
        }

        /*if (!m_Grounded)
         *  m_Rigidbody2D.AddForce(Physics2D.gravity * m_GravityScale);*/

        // If the player should jump...
        if ((m_Grounded || m_OnLadder) && jump)
        {
            // Add a vertical force to the player.
            m_Grounded = false;
            m_Anim.SetBool("Grounded", false);
            m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, 0.0f);

            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce), ForceMode2D.Force);


            // Prevents an issue that occasionally stops the player from jumping due to oddities with the ground check.
            StartCoroutine(DisableGroundCheck(0.1f));

            // Set a flag that says the player was running if they were
            m_RunLock = m_Running;

            playerStatistics.damageFromJump(GameConst.STAMINA_TO_JUMP);

            if (m_OnLadder)
            {
                m_OnLadder = false;
            }
        }

        if (m_OnLadder && Mathf.Abs(move) > 0.75f && ladderRef.GetOnTime() <= 0.0f)
        {
            m_OnLadder = false;
        }
    }