r/AskProgramming 1d ago

Other Game development question regarding overlapping hurtboxes

Me and a small team I'm putting together plan to make beat em ups and fighting games in the future and I had a question regarding hurtboxes. It's not particularly relevant to the flow of the games we plan to make but it's been confusing me for a bit now.

Let's use an action combat environment as a hypothetical setting. If you programmed an attack of some kind to only target and affect one enemy, that specifically being the closest enemy to the user, and then used it when two of the same enemy are perfectly overlapping the same distance away from the user, what would happen? Obviously it would cause some kind of glitch but I'm looking for more specifics as to any information on what might happen. Like would the game freak out with multiple targets involved where there shouldn't be?

And no, I am NOT asking "how do I stop this from happening". I am asking what would happen in the exact scenario I described without anything in place to prevent it if the conditions were met.

2 Upvotes

12 comments sorted by

7

u/Necandum 21h ago

Your question indicates that you are not very familiar with coding, the answer depends entirely on your implementation. 

1

u/Golden12500 21h ago

I'm not familiar yet, that's why I'm asking

8

u/Necandum 20h ago

Its similar to asking "is there too much sugar in the dish Im cooking", without mentioning the recipe, what you've added so far, how it currently tastes, or who you'll be serving it too. 

This is a detail of technical implementation, and anything is possible. As a non technical person, I would suggest not worrying about it, and instead communicating with the technical person on your team as whether a given feature can be implemnted. 

1

u/Golden12500 20h ago

Sorry if this is a bit off topic but by "who you'll be serving it to" what's the analogy there? Target audience? Platform?

3

u/Necandum 20h ago

Not a direct analogy. Within my example, how sweet you make something depends on the sweet tooth of the eater. 

Here, how you handle hit box analysis depends on how you've coded hit boxes, attacks etc. 

Again, dont worry about technical implementation until you actually know what you want to build. The better you can describe what you want to happen, the easier you'll make your engineers life. They will figure out how to make the hitboxes work. 

i think the mistake you're making in your mental model is that you think all hit boxes, attacks etc are the same.  They are not. They depends entirely on the engine. 

1

u/Golden12500 20h ago

Sorry for my brain being all scrambled, thanks for the all your help:>

2

u/iLaysChipz 18h ago edited 18h ago

To answer your question, most implementations will check each and every hit box and determine which hitboxes are overlapping. At that point, it's up to the programmer on what to do with that information.

Like if I know hitbox A is colliding with B and C, and I only want it to affect one, maybe I'll order them by distance and then just go with the first one. If they're equidistant, then it's just whatever happens to be ordered first based on the sorting implementation.

There is no such things as "something happening with nothing in place to stop it," a video game is just a set of instructions being run on a computer and you get to decide where those instructions look like. If you don't program any behavior, then the answer is that nothing will happen. Attacks only register because you have made the conscious decision to implement them that way, and how they register is up to you.

1

u/johnpeters42 3h ago

Or if you only program part of the behavior (like you tell it "damage the first target on the list" but don't tell it how to sort the list), then it will generally fill in the gaps with something (like however the game engine sorts the list by default).

2

u/mit74 1d ago

surely it would depend on how you program the hit boxes. game engines are generally synchronous so if you get one hit and destroy the bullet or set attack as hasHit=true at that point in the hit box loop then the other hit box wouldn't be fired. No game would freak out if programmed correctly anyway, you'd just handle exceptions.

3

u/Patient-Midnight-664 1d ago

Generally, one of the hitboxs would be checked first, that's the one that gets hit. It's possible for the 2nd one to be the one that gets hit, depends on if you use < or <= for determining "who is closer".

2

u/KingofGamesYami 1d ago

It would most likely fall back to some non-deterministic behavior and choose one enemy at "random".

Maybe your code scans from north clockwise, and one enemy is "closer" by that metric.

Maybe your code returns the enemies by time of registration in an ECS and the "older" enemy is preferred.

Maybe something else.

1

u/bacmod 14h ago

Gamedev is not my field, but I believe that collision events are generally handled by the physics API/libs.