• Advertisement
Sign in to follow this  

Fighting Game Input Manager

This topic is 4588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone: I am making a 2D fighting game, but am experiecing some difficutly in handling inputs. I am using DirectInput to register key presses within my game, although I plan to add Joystick support at a later date. Anyhow, I can register a down press or a right press from the keyboard, but I would like ot know how best to go abouts registering a down-right (IE diagonal) press from the keyboard. I have tried just checking to see if both down and right have been pressed, but this is not the solution I am seeking. My fighting game will follow the Capcom style of gameplay in terms of use of special moves, e.g. a quarter-circle forward motion plus punch may activate a special move. Therefore, I would ideally like to be able to detect the DOWN_RIGHT press as being a seperate entity from both DOWN and RIGHT. Does anyone have any ideas or web links I could visit to get a better insight into developing a Fighting Game input maanger? If anyone could help me please, I would appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
Never done anything like this myself, but, I've got a couple of ideas.

First of all, if you want to check if a DOWN_RIGHT has occured, you will, at some point have to check if DOWN and RIGHT happened at the same time.

To detect special combo moves? I suggest once you have the user input, shove it into a buffer that you clear every x seconds, or every so often when you get negligible (God, help me spell!) input, such as just a RIGHT or a LEFT for more than a second, something like that.

Then, every time you add something to the buffer, just check if it matches up with a combo that you have. (probably both buffer and the combo stored in vectors or lists, if you're using C++)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I agree with Endar here.

Place all of your key presses from the last 50ms in a buffer. Every 50ms, use this buffer to generate custom events, such as DOWN_RIGHT or even game-specific events such as PUNCH. Place this custom events into another buffer and check to see if a combo was made. Never let your combo buffer get too big.

Share this post


Link to post
Share on other sites
I am using a buffer already, but ideally the diagonal presses must be almost instantaneous. One such combination of key presses I wish to use in my game is the Forward, Down , Down_Forward + punch combination, IE a dragon punch. My initial intention is to set the check for a combination to be made every time a button is pressed. However the order in which moves were registered also plays an important part. QCF + P is different than Forwards, then QCF + punch. The first example should generate a fireball, the second should generate a Dragon Punch. At themoment, I can get my program to register a Down_Forward, and even the Down, Down_forward, Forward loop:

if(DOWN)
{
strcat(str, " DOWN");
}

if(DOWN&&RIGHT)
{
strcat(str, " DOWN_RIGHT");
}

if(UP)
{
strcat(str, " UP");
}


if(RIGHT)
{
strcat(str, " RIGHT");
}

At the moment I am just testing my code and getting it to print messages to screen due to different inputs received. However, because of the nature of this switch case, if one presses RIGHT, then DOWN, the DOWN seems to register before the right, at least when inputting the motions quickly. As I say, I think I need to be able to differntiate between directions on order to be abel to create my custom buffer effectively.

Share this post


Link to post
Share on other sites
Since good fighting games require VERY precise input detection, it is good that you are giving special attention to input. It has been the downfall of some (even commercial) fighting games in the past. (try doing a fireball in the original street fighter)

To the point. Since fighting games run at a constant FPS (its always been this way), usually 30 for 2d and 60 for 3d, what you should do is fetch user input once per frame. However, only changes should be added to the buffer. What you want the buffer to look like is
d for 5 frames
df for 3 frames
f for 2 frames
f+weak punch for 4 frames
neutral for 3 frames
(in the case of a street fighter 2 hadoken, for example).
It will be much easier to look at than a stream that looks like
d,d,d,d,d,df,df,df,f,f,f+wp,f+wp,f+wp etc.

The next thing i'd do, is to implement an automat builder that gets a series of legal moves for the character and builds an automat (state machine) that goes over a buffer and sends events when it detects that a legal move was performed.

A slightly different approach is to not use a buffer. If you did build a state machine, you can just create an instance of it in the beginning of the round, send the input to it each frame, and it will return the move that was triggered in the last frame of input if there was one. It might be slightly tricky to implement (state machine builder code sounds like a fun programming challenge actually, since its not a normal state machine).
Also, it wont return one move, but one move per state
lets say (street fighter 2 again) the input was d,df,f+punch
The automat would return that a hadoken was performed, but what if the character was in the middle of a jump ? What if he was knocked down?
Thats the reason that the automat machine should return a sort of structure,
with the action that should be performed for each legal state for the character (ground, air, blocking high, blocking low, knockdown, air knockdown, etc).
In that case, for d,df,f+p the state machine should return a struct that (logically) says
GroundMove:Hadoken
AirMove:Punch
GuardingHigh:Nothing (you could implement a reversal by making this not nothing... adds depth to the game)
KnockDown:Nothing
etc...
Then the game would get the struct from the state machine and check the action of the state that the character is currently in.


One of the tricky things (no matter which approach you'll choose) is allowing errors to a certain extent. (If you're making a 2d fighting game, you probably know the street fighter series). You can see that in earlier games they wanted the player to be a lot more precise than later games. Try doing a shoryuken in sf2 and in sfa3, and you'll see that you can be pretty sloppy in sfa3 and it will still work.


If you plan on making it a serious fighting game, you will have to pay attention to the input detection. It is critical in fighting games (im saying this because im a pretty serious fighting game player myself)


Anyway, yey its my first post.
hope i helped


[edit]
another thing. For the input detection of one frame, its good to use a bitmask. Perfect solution for the diagonal problem... just check for Down|Right etc... I would bet that most commercial games use this.

Share this post


Link to post
Share on other sites
Noman, many thanks for your post, you seem to have a good idea of what I am aiming to acheive. yes my game is a 2D game and I myself actually still play fighting games competeively at the Trocadero in London. As you say input is a vital part of a fighting game, and yes a game such as Rise of the Robots is an excellent example of a commerical game that gave no real thought for input and thus ended up with a crappy game. Anyway, although I get the gist of what you are saying, would it be possible to discuss some issues with you? If you have MSN, you can IM me on the_golden_gunman@hotmail.com . The issue I am particularly concerned with is that I eventually wish to create a "Parry" system as found in SF3: Third Strike, and how I would go about putting this in such a buffer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement