예제 #1
0
    protected virtual void Update()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y          = 0;
            controller.jumpDown = false;
        }

        grounded = controller.collisions.below;

        anim.SetBool("Grounded", grounded);
        anim.SetFloat("InputX", Mathf.Abs(input.x));
        sprite.flipX = input.x == 0 ? sprite.flipX : input.x < 0;

        if (input.y < 0)
        {
            controller.jumpDown = true;
        }

        if (jump && grounded)
        {
            velocity.y = maxJumpVelocity;
            jump       = false;
        }

        if (jumpDown && grounded)
        {
            velocity.y = maxJumpVelocity;
            jumpDown   = false;
        }

        if (jumpUp)
        {
            if (velocity.y > minJumpVelocity)
            {
                velocity.y = minJumpVelocity;
                jumpUp     = false;
            }
        }

        if ((attack && grounded) || (attackController.jumpingAttack && attack))
        {
            attackController.PerformAttack();
            attack = false;
        }

        if (guard && grounded)
        {
            attackController.GuardUp();
        }
        else
        {
            attackController.GuardDown();
        }

        float targetVelocityX = input.x * moveSpeed;

        velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }