#Attack Combo State is Glitchy

1 messages · Page 1 of 1 (latest)

supple briar
#

I'm unsure how to Debug and fix this. I have a MeleeState that allows the player to do a combo. After any of the attack animations _stateComplete = true which allows exiting out of MeleeState. So I can do a full combo of 3 attacks and the Debug will fire _stateComplete = true once. This is correct.

If I button mash the attack button to enter into MeleeState then after between 25-50 button presses eventually _stateComplete = true fires twice. What this looks like is the player begins to do the first attack animation but because _stateComplete = true it exits out of MeleeState immediately which goes to IdleState - looks glitchy.

public class MeleeState : PlayerState {
  private int _attackIndex;
  private bool _stateComplete;

  public MeleeState(PlayerSM sm) : base(sm) {}

  public override void Enter() {            
    _attackIndex = -1;
    _attackIndex++;
          
    _anim = _animancer.Play(_melee.Attacks[_attackIndex]);
    _anim.Events.OnEnd += OnAnimationEnd;
  }

  public override void Logic() {
    TryCombo();
    Debug.Log(_stateComplete);
  }

  public override void Exit() {
    _stateComplete = false;
    _attackIndex = -1;
  }

  private void TryCombo() {
    float t = _anim.NormalizedTime;

    if (_input.MeleeInput.WasPerformedThisFrame()) { 
      if ((t >= _melee.ComboStart && t <= _melee.ComboEnd)) {
        _attackIndex = (_attackIndex + 1) % _melee.Attacks.Count;
        _anim = _animancer.Play(_melee.Attacks[_attackIndex]);
        _anim.Events.OnEnd += OnAnimationEnd;
      }
    }
  }

  private void OnAnimationEnd() => _stateComplete = true;

  public override bool CanExitState() => _stateComplete;

  public override bool CanEnterState() =>      
    _input.MeleeInput.WasPerformedThisFrame();
  }
viscid plinth
#

just looks like you subscribe to _anim.Events.OnEnd multiple times, in Enter and perhaps multiple times in TryCombo

also you don't unsubscribe either on exit

#

so the method is just subscribed multiple times and also called multiple times

supple briar
supple briar
viscid plinth
# supple briar hmm I just tried but still same results. Any other thoughts?

I don't know how you want to combine the subscriptions, but you can do -=
before you do the next +=
but doing this on the same method is useless
if you subscribe in state enter you should probably unsubscribe in state exit though
if that is a commonly used event, maybe it's better to not have an event but to implement a method in your states for that instead, which is called.

supple briar
viscid plinth
# supple briar Hmm just tried this as i really felt it was gonna work but still glitchy. Maybe ...

Ever tried to build an actual animation state machine? This talk will guide you into the next level of state machine design and show you powerful features of Unity's Mecanim animation system state machine. We'll explore an actual character's animation state machine along with its event based combat system, how and why it was set up a particular...

▶ Play video
#

personally, I don't like animation controller management that much, so I might code everything in the attack state itself,
and maybe have a scriptable object (for example) to store related data
time intervals for when a combo during an animation can be input
type of input for combo
and animation state name to transition to (if just strings are used here, that is potentially a bit problematic but as long as animation state names don't change, it should be fine)

#

Btw, how is Animancer? I wanted to try it out, but i haven't had a project for it so far

supple briar
viscid plinth
# supple briar Animancer has been amazing! The list of pros are way too long to list. They have...

sounds great!
input buffering.. I feel like it can get in the way but in most cases it's useful
I think a common approach is to have something like a queue (first in first out collection) where you put in performed actions
and when you have an window you can act out of, like chaining combos, you check the actions in the queue if they match an accepted input,
if yes, you perform the input and remove the actions from the input queue

and probably good if inputs have a lifetime so that they aren't buffered for too long

supple briar
viscid plinth
#

woah, basically a full learning course

counting sounds like it just stores the current animation clip index (AttackIndex) - yeah that makes sense
seems like the buffer already implements concepts I mentioned
when you actually perform the input, you can add the input to the buffer

I don't know the contents of buffer, but seems like it handles state transition conditions inside and you just call update according to this?
I'd probably check out the input buffer code file to see how it works

supple briar
viscid plinth
#

does the full version not come with the source code? or only the dll?

supple briar
#

yeah it does....so I guess then the reasoning is simply I don't quite understand how to implement 🙂

#

I feel like I'm in this place of understanding a decent amount but not always able to interpret someone elses code and adapting to my own project

viscid plinth
#

hmmhh, if the documentation isn't detailed enough, looking at the source code is usually the best option
and always the most precise although it might be a big complex and overwhelming
reading into a different code base isn't easy either yeah
hope you can find out what you need,
I'd assume somewhere in the buffer you can pass transition conditions,
or otherwise there might be more relevant methods than just adding actions and updating the buffer that weren't described yet,
but dunno

supple briar
viscid plinth
supple briar
supple briar
supple briar
viscid plinth
#

nice!