r/howdidtheycodeit • u/Masterofdos • Nov 29 '23
Answered How do they code collision/hit detection and elevation in 2D beat em ups
Apologies if lumping two questions together is an issue but I didn't want to make two posts for one and a half questions.
- First Question: Hit/Hurtboxes -
Since you can move in 6 directions in most beat-em-ups, you're basically moving in pseudo 3d space. So then, are hitboxes and hurtboxes designed the same as other games or are they made thinner due to the perspective


My assumption would be that walking up and down is done on the y axis and jumping uses something else like a "height" variable. So making boxes thinner would prevent wonky hit registration like getting clipped by someone on a different plane than you
- Second Question: elevation -
This is the main question. Some Beat em ups, like the river city games, have elevation, walls and platforms you can jump on and you can jump on some throw-able objects (boxes, trashcans). How does this work with the unique perspective and 6 direction movement. It feels like it should be more obvious but I'm stumped on how this works
2
u/RetroGamer2153 Nov 30 '23 edited Nov 30 '23
As far as the NES, 6502 assembly only had INT's. Floats didn't exist. As such, Position.X & Position.Y weren't available. That didn't stop Dev's, though! Values were often stored in High/Low byte pairs (This allows a range from 0 to 65,535). In many games, the High Bytes often held whole numbers, while the Low Byte held the fraction.
Without any further dive into assembly, in Technos's games, hitbox collision boils down to 6 comparisons: 3 point checks, within 3 ranges (essentially a single point within a volume). Your instinct was correct: In modern engines 2D mode, it would be a thin rectangle, along Position.Y. (With a 2nd object's Position.Y to handle height collision.)
As far as platforming: When falling (after jumping), they would run a point check along the northern edge of the player's footprint. This allows the player to land on a higher(more northern) block with zero Z velocity (as in: a standstill jump). While walking, a more southern point compares for wall checks.
The newer River City Girls games, by WayForward, utilize full 3D physics in Orthogonal mode. All artwork are billboards. First, the background is laid. Invisible level polygons float on a "stage" (They don't have to match 1:1, depth-wise). Walls polygons are tweaked, until they feel right, and line up with the artwork.
Here's an awesome look into WayForward's level creation process: Youtube: River City Girls 2 - Behind the Scenes.
9
u/mack1710 Nov 29 '23
Well, first of all it’s good to understand a couple of things
You should imagine a 3D coordinate system describing positions separate from what’s being rendered on the screen as an ideal implementation.
For your first question, a successful implementation in a modern engine (say, Unity) would be to have all collisions as trigger boxes. An attack would register in that case for example if both characters are within a specific y distance of each other.
For your second, it’s hard to do that without an arbitrary axis describing the player height, that increases only when you jump or when you’re elevated through an area. The collider on some objects or obstacles in that case would block characters below a certain “height”, and would allow them to be lifted by it if they’re above it in “height”
I’d abstract these concepts as reusable components. You don’t want to deal with this in a per-object basis. All the best.
7
u/MetallicDragon Nov 29 '23
I don't know whether any game does this, but you could just do 3d hitboxes. The math isn't that much more complex or computationally expensive, and you'd just project every object to 2d when rendering it.
Otherwise, for the height at least, you could just fake it by having a "height" variable, and only letting things within a certain height distance hit eachother, but that's 90% of the way to just being 3d hit boxes anyway.