Only getting the first animation in the 3rd person game course for the combo

Much like In ComboAttack Only the first animation is playing, I’ve implemented the code provided and it never plays past the first animation. Like that other guy, it always shows IsInTransition as being true. And, when the animation finishes, it hits that third state in GetNormalizedTime, indicating that we’re not in a transition and that the next state does not have the attack tag. I tried debugging it on my own, but I’m at my wit’s end. Is there at least a good way to see what that next animator state is supposed to be?

For the Attack animations, all of them should have the tag “Attack”, so you can properly test the state.

Paste in your PlayerAttackState here. If your GetNormalizedTime() method is in a base state, be sure to include that as wall.

1 Like

PlayerAttackingState.cs

> using System;
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
> 
> public class PlayerAttackingState : PlayerBaseState
> {
>     private Attack CurAttack;
>     private float previousFrameTime;
>     public PlayerAttackingState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
>     {
>        CurAttack = stateMachine.Attacks[attackIndex];
>     }
> 
>     public override void Enter()
>     {
>         stateMachine.Animator.CrossFadeInFixedTime(CurAttack.AnimationName, CurAttack.TransitionDuration);
>     }
> 
>     public override void Exit()
>     {
>         
>     }
> 
>     public override void Tick(float deltaTime)
>     {
>         Move(deltaTime);
> 
>         FaceTarget();
> 
>         float normalizedTime = GetNormalizedTime();
> 
>         if (stateMachine.InputReader.IsAttacking)
>         {
>             Debug.Log(String.Format("Tick norm_time {0}", normalizedTime));
>         }
> 
>         if (normalizedTime > previousFrameTime && normalizedTime < 1f) {
>             if (stateMachine.InputReader.IsAttacking)
>             {
>                 TryComboAttack(normalizedTime);
>             }
>         }
>         else
>         {
>             // Go back to locomotion
>         }
> 
>         previousFrameTime = normalizedTime;
>     }
> 
>     private void TryComboAttack(float normalizedTime)
>     {
>         Debug.Log(String.Concat("Entering Combo Attack for ", CurAttack.AnimationName));
>         // Debug.Log(String.Format("ComboStateIndex: {0} ComboAttackTime: {1}", CurAttack.ComboStateIndex, CurAttack.ComboAttackTime));
>         if (CurAttack.ComboStateIndex == -1) { return; }
> 
>         Debug.Log(String.Format("normalizedTime: {0} ComboAttackTime: {1}", normalizedTime, CurAttack.ComboAttackTime));
>         if (normalizedTime < CurAttack.ComboAttackTime) { return; }
> 
>         Debug.Log("Next Attack?");
>         stateMachine.SwitchState(new PlayerAttackingState(stateMachine, CurAttack.ComboStateIndex));
>     }
> 
>     private float GetNormalizedTime()
>     {
>         AnimatorStateInfo currentInfo = stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
>         AnimatorStateInfo nextInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);
> 
>         if (stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag("Attack"))
>         {
>             Debug.Log(String.Format("In transition, time {0}", nextInfo.normalizedTime));
>             return nextInfo.normalizedTime;
>         }
>         else if (!stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag("Attack"))
>         {
>             Debug.Log(String.Format("Not in transition, time {0}", currentInfo.normalizedTime));
>             return currentInfo.normalizedTime;
>         }
>         else
>         {
>             Debug.Log(String.Format("Transition state: {0}, isAttack: {1}", stateMachine.Animator.IsInTransition(0), nextInfo.IsTag("Attack")));
>             return 0;
>         }
>     }
> }

It does include a lot of debug statements from where I was trying to track down the issue.

Huh. After going through the next lecture (which is experiencing some of the same problems), I tried removing the “normalizedTime > previousFrameTime” from Tick and now, I’m in that state of it kind of stuttering and not starting an animation, but on the other hand, now I get one of the three attacks based on how long I hold the button down.

OK, and I think I see why I’m always in the state of there being a next transition, namely that I am, of course, transitioning from the Idle animation. Still not certain why it keeps ending at about 0.6 into the animation, but I’m zeroing in on understanding, I think. Still not 100% certain how I got into the jittering bit… it seems to be restarting the attack state repeatedly with the mouse button held down.

OK, I’m a bit of an idiot. I had a copy-paste error in getNormalizedTime where I was checking nextInfo for whether it was an attack, even if I wasn’t currently in transition. Instead, it was supposed to be for currentInfo. Now, I’m back to the stuttering attack, which I think the next lecture accidentally introduced, and then fixed. Probably will reply back in a moment with that fix.

This piece of code was something we used in the prototype that we decided we didn’t need, but still made it through to the final lecture anyways. It’s unnecessary because GetNormalizedTime deals with the transitions and gets the proper time.

I’m nto sure what’s causing the jittering… at least not something I can see in the code.

I figured out the jittering. It was when I was trying to debug the problem after posting the problem here, I added a bit of code in TryComboAttack that I thought was keeping it from ending the combo upon normalizedTime being 0, but actually resulted in the combo instantly switching every time. It was not the same error as gets introduced partway into module 16.

I have everything working now except that the third attack I picked has a slight sideways movement that I need to account for.

Thank you for your help. Sorry that I didn’t post additional code once I hit that jitter state. It might have simplified things.

That could be movement baked into the animation itself. Mixamo animations have the advantage of being free, but sometimes the disadvantage of not working the way we want them to.

Privacy & Terms