Attacking animation stuck at the end

Hello,

After attacking, the state change back to the PlayerFreeLookState but the animation get stuck at the end of the attacking one. I can move but the animation of idle and running doesn’t work again.

My PlayerAttackingState :

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

        float normalizedTime = GetNormalizedTime();
        
        if( normalizedTime <1f)
        {
            if (stateMachine.InputReader.IsAttacking)
            {
                TryCombatAttack(normalizedTime);
            }
        }
        else
        {
            stateMachine.SwitchState(new PlayerFreeLookState(stateMachine));
        }
        previousFrameTime = normalizedTime;
    }

My PlayerFreeLookState

public override void Tick(float deltaTime)
    {

        if (stateMachine.InputReader.IsAttacking)
        {
            stateMachine.SwitchState(new PlayerAttackingState(stateMachine, 0));
            return;
        }

        Vector3 movement = CalculateMovement();

        Move(movement * stateMachine.FreeLookMovementSpeed, deltaTime);

        //stateMachine.Controller.Move(movement * stateMachine.FreeLookMovementSpeed * deltaTime);

        if (stateMachine.InputReader.MovementValue == Vector2.zero)
        {

            stateMachine.Animator.SetFloat(FreeLookSpeedHash, 0, AnimatorDampTime, deltaTime);

            return;
        }

        stateMachine.Animator.SetFloat(FreeLookSpeedHash, 1, AnimatorDampTime, deltaTime);
        FaceMovementDirection(movement, deltaTime);
        

        Cursor.lockState = CursorLockMode.Locked;

    }

I removed the targeting script because I don’t want to use it.

Thank you :slight_smile:

The issue is most likely in the GetNormalizedTime script… more to the point, it’s probably not the script, but the setup on the attacks.
Make sure that all three attacks have a Tag on them of Attack (or whatever tag you used in GetNormalizedTime. Without that tag, the function will never reach the else statement in your Tick method.

Thanks for the quick answer :slight_smile: I have checked what you advised me to do.
The function reach the else statement because my player go back to the PlayerFreeLookState since I can move after attacking. Only the animation is stuck.

If the illustration is right, the Animator is stuck at the end of the Attack3 state…
We enter the FreeLookBlendTree automatically when the game starts, so it’s quite possible that the name of the FreeLookBlendTree is misspelled either in your call to start the animator or in the Hash set up to replace the name in the call to CrossFadeAnimation. This makes it so we get into the state automagically when the game starts, but can’t return to it because of a misspelling.

You might be getting warnings that no such state exists in the console… Make sure that the name for the Blend Tree in your PlayerFreeLookState is “FreeLookBlendTree”

Thank you very much !
The “stateMachine.Animator.Play(FreeLookBlendTreeHash);” line was missing in my script !

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

Privacy & Terms