r/howdidtheycodeit • u/hotchocolateisascam • 1d ago
what programming patterns are used in fighting games?
It seems like fighting games are pretty complex to program. I mean having an input that determines a move is the basis, but there seems like a lot of complication in terms of how to detect who hit who at what time and how one move is interrupted by another. Anyone have any experience with the topic, and can tell me about what strategies fighting game devs use to do this?
26
Upvotes
28
u/HyperCutIn 1d ago
Dig into how Mugen characters are coded in the engine. It's not gonna be the exact same with other fighting games, but basically each character has a gigantic state machine that transitions characters into different states depending on different conditions. Input processing is handled in what's effectively one of Mugen's three "universal states" that are running at all times, as opposed to regular states that have limited transitions to other states. Of course, since certain moves have restrictions on when you can use them, they're limited by conditionals, drawn from Mugen's "trigger" code. Stuff like hit detection and gethit states are all under the hood for the most part, but I'd imagine they're handled similarly such that the engine can transition a character from almost any of their states (whether it be them idling, moving, attacking, etc.) into the appropriate gethit state.
11
u/Ashamed-Subject-8573 1d ago
Generally speaking, each animation has frames to it. And the frames have not just character data, but also "hurt boxes." Those are tested to see if they intersect the other character's "hit box," to determine a hit.
Honestly the more interesting thing to me is programming enemy AI. You can make it hard by cheating, but making actually fun-to-duel AI seems to be pretty hard.
3
u/WorkingMansGarbage 1d ago
Something that might help without needing to know technical details is learning more about the gameplay systems' more obscure aspects.
Like, for instance ; unlike what I thought, frame advantage is usually not determined by literally setting the number of hit/blockstun frames for a hitbox, at least not in Guilty Gear. Instead they give moves one of five Attack Levels that have their own values; the variance in frame advantage then comes from animation length. It's less control, but a lot less work setting individual variables as I would have done.
Understanding a game system in and out as a player helps understand it on a technical level.
13
u/jax024 1d ago
They’re essentially state machines that run on a tick by frame.
4
u/Ronin-s_Spirit 1d ago edited 1d ago
I think it's about coded mechanics and not programming patterns. One mechanic virtually any game uses is "state machines", which is a graph of what you are doing right now and what you can do next considering the state you're in.
And of course there will be a rendering loop and an event loop, the rendering has to run at a fixed framerate (or try to anyway) and the event loop can run as fast as it wants to because it doesn't actually show anything it just changes program state. Older games mushed together render and simulation (logic) so you get stuff like faster input processing in Warframe at higher fps, or more enemy spawns.
1
u/detroitmatt 1d ago
you start with a state machine for each character. the state machine's inputs include that player's controller inputs, whether they got hit this frame, and maybe a few other variables depending on the game. with each state you associate hitbox+hurtbox data. most interactions can be handled directly by the state machine. for some particularly unique movies, you need to bypass the state machine at the engine level.