are you using Enhance Input (engine Version 4.27 or later and forced in 5.2 or later) or are you using the project settings method (engine version 5.1 or earlier)? (I will be assuming Enhanced Input, but different steps would need to be followed for the Project Setting method)
is this going to be using like a joystick or like directional keys?
the “easiest way” that includes all possible inputs is that you will want to maintain the last N
inputs from the player (for the enhanced Input system what is typically used for directional input returns a Vector2<float>
, and a directional pad has 3 potential states {-1. 0. 1} as outputs while a joystick can be any value on the bounds of {-1, 1} for each piece to the Vector2<float>
)
typically for movement keys we only care about when it is giving a non-Zero value, but if this is supposed to be like
Player pushes Left -> player neutrals direction -> Player Pushes Left
then you will want to bind to Completed
and Canceled
as signifying the “released” state
to compare the last few inputs together I would suggest creating some kind of
enum EInputState{
None, Left, Up_Left, Up, Up_Right, Right, Right_Down, Down, Left_Down,
// you may want to list the other input keys you want to be queueing
};
the directional inputs are probably the trickiest to figure out, but you want to take the Vector2
and check each the X (Left/Right) and the Y (Up/Down or Back/forward) to see what direction is being used something like
tempD1;
if( input.y > 0.01f ){ tempD1 = Up; }
else if( input.y < -0.01f ) { tempD1 = Down; }
else { tempD1 = None; }
tempD2;
if( input.x > 0.01f ){ tempD2 = Right; }
else if ( input.x < -0.01f ) { tempD2 = Left; }
else { tempD2 = None; }
curDirection
if( (tempD1 == None) && (tempD2 == Left) ) { curDirection = Left; }
else if ( tempD1 == None ) && (tempD2 == Right ) ) { curDirection = Right; }
else if ( tempD1 == Up ) && (tempD2 == None ) ) { curDirection = Up; }
else if ( tempD1 == Down ) && (tempD2 == None ) ) { curDirection = Down; }
...
else { curDirection = None; }
this will be triggered once per frame (faster then the average human response time) so you will probably be tracking whenever there is a change, rather then adding each and every one to like a Queue.
then create like an Actor Component where we are going to be faking a queue ( in C++ a TQueue
is an already available Container, but this is not immediately available to blueprints though this is a fundamental Data Structure in CompSci ) if you need additional help on making a queue then I can elaborate further.