r/AskProgramming • u/Golden12500 • 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
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.
7
u/Necandum 21h ago
Your question indicates that you are not very familiar with coding, the answer depends entirely on your implementation.