public void shouldNotFlipWhenPositiveNumAndFacingRight()
        {
            float move        = 1;
            bool  facingRight = true;
            bool  shouldFlip  = CharacterControllerLogic.shouldFlip(move, facingRight);

            Assert.AreEqual(shouldFlip, false);
        }
예제 #2
0
    public void Move(float move, bool crouch, bool jump)
    {
        // If crouching, check to see if the character can stand up
        crouch = CharacterControllerLogic.standCheck(crouch, Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround));

        //only control the player if grounded or airControl is turned on
        if (m_Grounded || m_AirControl)
        {
            // If crouching
            if (crouch)
            {
                if (!m_wasCrouching)
                {
                    m_wasCrouching = true;
                    OnCrouchEvent.Invoke(true);
                }

                // Reduce the speed by the crouchSpeed multiplier
                move *= m_CrouchSpeed;

                // Disable one of the colliders when crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = false;
                }
            }
            else
            {
                // Enable the collider when not crouching
                if (m_CrouchDisableCollider != null)
                {
                    m_CrouchDisableCollider.enabled = true;
                }

                if (m_wasCrouching)
                {
                    m_wasCrouching = false;
                    OnCrouchEvent.Invoke(false);
                }
            }

            // Move the character by finding the target velocity
            Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
            // And then smoothing it out and applying it to the character
            m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);

            if (CharacterControllerLogic.shouldFlip(move, m_FacingRight))
            {
                Flip();
            }
        }
        // If the player should jump...
        if (m_Grounded && jump)
        {
            //add audio when jumping
            soundManager.PlaySound("jump");
            // Add a vertical force to the player.
            m_Grounded = false;
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }
    }