#Need help with Input Buffering

1 messages · Page 1 of 1 (latest)

vagrant axle
#

how would you guys approach integrating input buffering with this implementation? The goal is to do _ability.Perform(), then if the player presses input again within a specific buffer, then trigger _ability.Perform() again BUT only after the 1st Perform is complete. I have a bool indicating start and end with isPerformingAbility

public class DashAbility : Ability {

        private readonly Player _player;
        private readonly IDash _ability;
        private readonly IInput _input;

        public DashAbility(Player player, IDash ability, IInput input) {
            _player = player;
            _ability = ability;
            _input = input;
            _input.OnDash += TryAbility;
        }

        public override void TryAbility() {
            if (!NeedsMet()) return;
            _ability.Perform();
        }

        private bool NeedsMet() => _player.CanDash;
    }
native violet
vagrant axle
native violet
#

I would have a coroutine that delays until the end of the dash, which, after the delay, checks a bool that has been updated with the buffer status, and runs the dash again if that buffer is true

#

so, basically

bool dashing, dashBuffer;
float dashTime;

public override void TryAbility()
{
  if (!Needsmet()) return;

  if (dashing) dashBuffer = true;
  else _ability.Perform();
}

IEnumerator bufferCheck()
{
  yield return new WaitForSeconds(dashTime);

  if (dashBuffer && NeedsMet()) _ability.Perform();
  else dashing = false;
}

and StartCoroutine(bufferCheck()) runs in _ability.Perform(), or a wrapper that calls them sequentially

native violet
#

Just curious, did this work? @vagrant axle

vagrant axle
# native violet Just curious, did this work? <@908460054431293440>

so I managed to get the input buffering working with this. What do you think?

private void Update() {
            if (_nextAbility == null) {
                return;
            }

            if ((Time.time - _nextAbilityTime) >= _nextAbilityTimeMax) {
                _nextAbility = null;
                return;
            }

            if (!_character.Parameters.IsPerformingAbility) {
                _nextAbility.Invoke(true);
                _nextAbility = null;
            }
        }

        private void QueueAbility(Action<bool> ability, float time, float bufferTime) {
            if (_character.Parameters.IsPerformingAbility) {
                _nextAbility = ability;
                _nextAbilityTime = time;
                _nextAbilityTimeMax = bufferTime;
            }
            else {
                ability.Invoke(false);
            }
        }
native violet
vagrant axle
native violet
verbal vigil
#

Personally I would create an enum that stores the character state (i.e. idle, jumping, dashing) etc.
When the player presses an input you could then perform the behaviour relevant to the current state

native violet
verbal vigil
native violet
#

First of all, this person is trying to make a dynamic ability system, using an enum that tracks each ability like that wouldn't easily allow for abilities to be enabled and disabled as easily as just a class connected to an object

#

Second of all, how would this solve the input buffering issue?

verbal vigil
#

Agree completely on first point.
I was just worried that if the player's dash is interrupted (ex collides into obstacle) then the second dash might not work as intended. I guess you could account for this sort of thing in your NeedsMet() method though