Ejemplo n.º 1
0
        void UpdateWalking(Vector2 inputDirection)
        {
            if (isSwimming)
            {
                yVel += gravity / 2f;
            }
            else
            {
                yVel += gravity;
            }

            if (isGrounded && inputs[5])
            {
                yVel = jumpForce;
            }

            if (isSwimming && inputs[5])
            {
                yVel += swimmForce;
            }

            Vector3 updateVel = (transform.right * inputDirection.x + transform.forward * inputDirection.y * (inputs[6] ? 1.5f : 1f)) * speed;

            updateVel += new Vector3(0f, yVel, 0f);

            isSwimming          = false;
            transform.position += new Vector3(0, updateVel.y, 0);
            if (PlayerCollider.Collision(transform, out isGrounded, out bool swimming))
            {
                transform.position -= new Vector3(0, updateVel.y, 0);
                yVel = -2f * Time.fixedDeltaTime;
            }
            isSwimming |= swimming;

            transform.position += new Vector3(updateVel.x, 0, 0);
            if (PlayerCollider.Collision(transform, out bool _, out swimming))
            {
                transform.position -= new Vector3(updateVel.x, 0, 0);
            }
            isSwimming |= swimming;

            transform.position += new Vector3(0, 0, updateVel.z);
            if (PlayerCollider.Collision(transform, out bool _, out swimming))
            {
                transform.position -= new Vector3(0, 0, updateVel.z);
            }
            isSwimming |= swimming;
        }