In ComboAttack Only the first animation is playing

Hi everyone!

When I try to attack in a combo, I run into a problem. Only the first animation is played.

PlayerAttackingState.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAttackingState : PlayerBaseState
{
     private float previousFrameTime;

    private Attack attack;

    public PlayerAttackingState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
    {
        attack = stateMachine.Attacks[attackIndex];
    }

    public override void Enter()
    {
        stateMachine.Animator.CrossFadeInFixedTime(attack.AnimationName, attack.TransitionDuration);
    }

    public override void Tick(float deltaTime)
    {
        Move(deltaTime);

        FaceTarget();

        float normalizedTime = GetNormalizedTime();

        if (normalizedTime > previousFrameTime && normalizedTime < 1f)
        {
            if (stateMachine.InputReader.IsAttacking)
            {
                TryComboAttack(normalizedTime);
            }
        }
        else
        {
            // go back to locotmotion
        }

        previousFrameTime = normalizedTime;
    }

    public override void Exit()
    {

    }

    private void TryComboAttack(float normalizedTime)
    {
        if (attack.ComboStateIndex == -1) { return; }

        if (normalizedTime < attack.ComboAttackTime) { return; }

        stateMachine.SwitchState
        (
            new PlayerAttackingState
            (
                stateMachine,
                attack.ComboStateIndex
            )
        );
    }

    private float GetNormalizedTime()
    {
        AnimatorStateInfo currentInfo = stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
        AnimatorStateInfo nextInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);

        if (stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag("Attack"))
        {
            return nextInfo.normalizedTime;
        }
        else if (!stateMachine.Animator.IsInTransition(0) && currentInfo.IsTag("Attack"))
        {
            return currentInfo.normalizedTime;
        }
        else
        {
            return 0f;
        }
    }


}

I’m pretty sure the codes are the same. What could be causing this issue?

How did you configure the combo? Do you have the combo sequence defined in `ComboStateIndex’?

1 Like

Hi thanks for reply :smiling_face_with_three_hearts:, If I understand you well, by “sequence,” you mean config in “inspector.”
This is my inspector Config.
Screenshot 2022-11-28 000712


Screenshot 2022-11-28 001037

I am grateful for your time.

Yeah, that’s what I meant. Everything looks fine, here. What does the attack action look like in your InputReader?

1 Like

When I changed the inspector value in the scene, it wasn’t the same as my prefab, but it is now, and it fixed my issue. Thank you for your time. :heart:

Oh, ok. No problem.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms