Exemple #1
0
    void UpdateCombat()
    {
        if (lightAttackCooldownTimer > 0)
        {
            lightAttackCooldownTimer -= Time.deltaTime;
            if (lightAttackCooldownTimer < 0)
            {
                lightAttackCooldownTimer = 0;
            }
        }

        if (!_characterInputController)
        {
            return;
        }

        CharacterInputController.CharacterInput characterInput = _characterInputController.characterInput;

        if (characterInput.block && !_characterMovementController.IsDodging && !isChargingSpirit &&
            !isSpecialAttackActive)
        {
            if (!isBlocking)
            {
                if (Block())
                {
                    isBlocking = true;
                    _animator.SetBool("isBlocking", true);
                }
            }
        }
        else
        {
            if (isBlocking)
            {
                Unblock();
                isBlocking = false;
                _animator.SetBool("isBlocking", false);
            }
        }

        if (!isBlocking && !_characterMovementController.IsDodging && !isSpecialAttackActive)
        {
            if (characterInput.specialAttack)
            {
                if (chargedSpirit > 0)
                {
                    SpecialAttack(chargedSpirit);
                    isSpecialAttackActive = true;

                    _animator.SetTrigger("Special");
                    StartCoroutine(OnSpecialAttackUnleashed());

                    CancelSpiritCharge();
                }
            }

            if (characterInput.specialAttackCharge)
            {
                if (!isChargingSpirit && spirit >= minSpiritConsumption && canChargeSpirit)
                {
                    StartingSpiritCharge();
                    isChargingSpirit = true;

                    spirit       -= minSpiritConsumption;
                    chargedSpirit = minSpiritConsumption;

                    SpiritChargingAudioSource.Play();

                    _animator.SetBool("isCharging", true);
                }
            }
            else
            {
                if (isChargingSpirit)
                {
                    CancelSpiritCharge();
                }
            }

            if (characterInput.lightAttack)
            {
                if (!isChargingSpirit && lightAttackCooldownTimer <= 0)
                {
                    if (LightAttack())
                    {
                        _animator.SetTrigger("Light");
                        lightAttackCooldownTimer = totalLightAttackCooldownTime;
                    }
                }
            }
        }
        else
        {
            if (isChargingSpirit)
            {
                CancelSpiritCharge();
            }
        }

        if (isChargingSpirit)
        {
            ChargeSpirit();
        }
    }
    void Move()
    {
        if (!_characterInputController)
        {
            return;
        }

        Vector3 cameraForward = ArenaManager.Instance.arenaCamera.transform.forward;
        Vector3 cameraRight = ArenaManager.Instance.arenaCamera.transform.right;

        cameraForward.y = 0;
        cameraRight.y = 0;

        CharacterInputController.CharacterInput characterInput = _characterInputController.characterInput;

        float xDelta = characterInput.horizontal * speed;
        float zDelta = characterInput.vertical * speed;

        Vector3 movementDelta = (cameraRight * xDelta) + (cameraForward * zDelta);

        if (_characterCombatController.isBlocking || _characterCombatController.isChargingSpirit ||
            _characterCombatController.isSpecialAttackActive)
        {
            movementDelta = Vector3.zero;
        }

        Vector3 finalPos = transform.position + movementDelta;

        Vector3 newPos = Vector3.Lerp(transform.position, finalPos, Time.fixedDeltaTime);
        Quaternion newRotation = transform.rotation;

        if (!isDodging && characterInput.facingDir.magnitude > 0)
        {
            newRotation = Quaternion.LookRotation(characterInput.facingDir, transform.up);
        }

        Vector3 moveDir = transform.forward;
        if (movementDelta.magnitude > 0f)
        {
            moveDir = finalPos - transform.position;
            moveDir.y = transform.position.y;

            _animator.SetBool("isWalking", true);

            if (Vector3.Angle(transform.forward, movementDelta) > 90f)
            {
                _animator.SetBool("isWalkingBack", true);
            }
            else
            {
                _animator.SetBool("isWalkingBack", false);
            }
        }
        else
        {
            _animator.SetBool("isWalking", false);
        }

        newRotation = Quaternion.Lerp(transform.rotation, newRotation, rotationSpeed * Time.fixedDeltaTime);
        newRotation.x = 0;
        newRotation.z = 0;

        transform.position = newPos;
        transform.rotation = newRotation;

        if (characterInput.dodge && !_characterCombatController.isChargingSpirit &&
            !_characterCombatController.isSpecialAttackActive)
        {
            isDodging = true;
            dodgingDir = moveDir.normalized;
            dodgingDir.y = 0;
            dodgeStart = Time.time;

            _animator.SetTrigger("Roll");
        }
    }