What Happens When Two Enemies Are Equally Close to a Single-Target Attack?

0
0
Asked By VelvetOrbit42 On

My small team is planning to make beat 'em ups and fighting games, and I'm trying to understand how targeting behaves in an edge case. Imagine an action-combat game where an attack is programmed to affect only one enemy: specifically, the enemy closest to the attacker. If two identical enemies are perfectly overlapping and both are exactly the same distance away, what would happen when the attack is used? Would the game select one of them, affect both, produce an error, or behave unpredictably? I'm asking what the result would be if no special handling had been added for this situation—not how to prevent the overlap.

3 Answers

Answered By LumenPine31 On

In a typical implementation, the game checks candidates in some order and keeps the best match found so far. Since both enemies have the same distance, the first one encountered may remain selected. The order could come from a list, entity registration order, collision-system results, or something similar. If the comparison uses a strict less-than check, the first candidate usually wins; using less-than-or-equal could cause the later candidate to replace it.

Answered By CedarMoth7 On

There isn’t one universal result because it depends entirely on how the targeting code is written. The engine usually won’t automatically “freak out”; your code will follow whatever ordering and comparison rules you gave it. If the logic assumes there can only be one closest target, the result could be an exception or an arbitrary selection.

VelvetOrbit42 -

That makes sense. I’m not familiar with the implementation details yet, which is why I wanted to know what kinds of outcomes are possible.

Answered By QuietHarbor86 On

If the code doesn’t define a tie-breaker, it may look random even though it’s following a hidden ordering. One enemy might consistently win because it was created first or appears first in the engine’s query results, while a different implementation might choose the other one. Depending on the API and assumptions in the code, an invalid result or error is also possible, but two overlapping targets don’t inherently cause the game to fail.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.