ID:2056693
 
(See the best response by Ter13.)


Problem description:
How can I handle hitboxes in byond. Like "HatShot","ArmShot", atc...
I know I have a deal with obounds, and bonds .

I'm not really looking for a code based explanation, although that would be great, but some pointers in the right direction be appriciated.
Best response
It's probably better to abstract it. Simulating that kind of accuracy is not ideal in 2D games.

Detecting which part of the player's icon was hit is more than likely not going to result in values that your player will agree with.

A general solution would be to determine the relative directions of the mob and the projectile that hit them. Provided their angles are equal within 45 degrees, it's a hit from the back. If their angles are offset by 45 to 135 degrees, it is a hit from the side. Otherwise, it is a hit from the front.

You can take this a bit further with a sidescroller than you can with a topdown or 3/4ths game. In a sidescroller, determining a head, body, leg shot could be done simply by calculating the y offset of the projectile from the mob's feet. If the projectile is greater than a certain threshold, it is a headshot. if it is greater than a second threshold, it is a body shot. If it is greater than 0, it is a hit to the legs.

For 3/4ths or topdown games, the concept doesn't make a lot of sense at all. Many games choose to abstract this behind a sort of hidden random percentage chance to hit a certain body part from certain angles with each hit having different effects.

But again, for a 2D pixel game, bodypart specific hitboxes are probably going to wind up being more trouble than they are worth. After all, even the art styles that lend themselves to 2D games tend to emphasize heads and torsos much more than arms and legs, so creating a system that tracks which bodypart you hit based on where you click is going to disproportionately result in the most vulnerable area (the head and torso) being far more likely to be hit than the arms or legs. The consequences of that problem should be pretty obvious.