Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make projectile targeting code anatomy indepedent, aim for center of mass #56104

Merged

Conversation

anothersimulacrum
Copy link
Member

@anothersimulacrum anothersimulacrum commented Mar 14, 2022

Summary

Features "Make projectile targeting anatomy agnostic, aim for center of mass"

Purpose of change

The projectile targeting code formerly cared too much about our anatomy, and that would not do if we want to change our anatomy. Additionally, instead of sensibly aiming for the center of mass, with good shots, the target would randomly switch to the head.

Describe the solution

Replace the old "torso or arms or legs, and then head if you got a good hit" logic with an anatomy dependent projectile targeting function.

This function uses the connection relationships of the body parts in the anatomy to generate a graph. At the center of the graph is the body part with the largest hitsize, Which is treated as the center of mass.
To select a bodypart, a path to an end of the graph is first chosen, with what branch to take chosen in a random fashion, weighted by the relative hitsize of the possible next limbs.
Then, the total weight of that path is determined, and used to scale the accuracy value passed in. Based on the accuracy value (lower is closer to center of mass), we walk down the path, stopping on whatever bodypart is the last one before it is too expensive to continue.

For random shots, this results in these percentage chances to hit various bodyparts:

hands:  0.69%
feet :  0.91%
arms :  5.98%
legs :  5.92%
mouth:  0.04%
eyes :  0.04%
head :  0.71%
torso: 72.22%

For actual shots, from 8 m249 turrets firing 1600 rounds from 36 tiles away.
before:

    813 arm_l (20.7%)
    864 arm_r (22.0%)
    263 leg_l ( 6.7%)
    257 leg_r ( 6.6%)
   1726 torso (44.0%)
total: 3923

after:

     73 arm_l  ( 1.9%)
     89 arm_r  ( 2.3%)
      1 foot_l ( 0.025%)
      1 foot_r ( 0.025%)
      3 head   ( 0.08%)
     82 leg_l  ( 2.1%)
     88 leg_r  ( 2.3%)
   3511 torso  (91.2%)
total: 3848

See files under additional context for some data.

Describe alternatives you've considered

In practice, the effective result is that body parts other than the torso are rarely hit. It may make sense in the future to use some other value than hit_size for weighting.

Testing

See tests.
Also, get shot (by turrets or NPCs), and shoot some NPCs and zombies.

Additional context

Here's some data - the result of being fired at by an m249 turret 36 tiles away:
This is a log of ~3800 hits, with the bodypart hit on each line
hits.log

     82 arm_l
     92 arm_r
      1 hand_r
      4 head
     84 leg_l
     77 leg_r
   3506 torso

These are similar, but shows info on the accuracy values passed to the hit function:
parts1.log

     69 arm_l
     64 arm_r
      1 foot_r
      2 head
     73 leg_l
     82 leg_r
   3571 torso

parts2.log

     73 arm_l
     89 arm_r
      1 foot_l
      1 foot_r
      3 head
     82 leg_l
     88 leg_r
   3511 torso

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. labels Mar 14, 2022
@anothersimulacrum anothersimulacrum added Game: Balance Balancing of (existing) in-game features. Mechanics: Aiming Aiming, especially aiming balance Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics labels Mar 14, 2022
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Mar 14, 2022
@anothersimulacrum anothersimulacrum force-pushed the hit-me-with-your-best-shot branch from 2473e36 to 8208424 Compare March 15, 2022 02:11
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 15, 2022
Replace the old "torso or arms or legs, and then head if you got a good
hit" logic with an anatomy dependent projectile targeting function, to
move us towards being able to change our anatomies.

This function uses the connection relationships of the body parts in the
anatomy to generate a graph. At the center of the graph is the body part
with the largest hitsize, Which is treated as the center of mass.
To select a bodypart, a path to an end of the graph is first chosen,
with what branch to take chosen in a random fashion, weighted by the
relative hitsize of the possible next limbs.
Then, the total weight of that path is determined, and used to scale the
accuracy value passed in. Based on the accuracy value (lower is closer
to center of mass), we walk down the path, stopping on whatever bodypart
is the last one before it is too expensive to continue.

For random shots, this results in these percentage chances to hit various
bodyparts:
hands:  0.69%
feet :  0.91%
arms :  5.98%
legs :  5.92%
mouth:  0.04%
eyes :  0.04%
head :  0.71%
torso: 72.22%

In practice, the effective result is that body parts other than the
torso are rarely hit. It may make sense in the future to use some other
value than hit_size for weighting.

This also means that monsters will only be able to bleed on their torso
and head, as they are the only parts of a monster anatomy.
@anothersimulacrum anothersimulacrum force-pushed the hit-me-with-your-best-shot branch from 8208424 to 155507e Compare March 17, 2022 20:59
@kevingranade kevingranade merged commit b91dbc0 into CleverRaven:master Mar 27, 2022
@anothersimulacrum anothersimulacrum deleted the hit-me-with-your-best-shot branch March 27, 2022 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. Game: Balance Balancing of (existing) in-game features. json-styled JSON lint passed, label assigned by github actions Mechanics: Aiming Aiming, especially aiming balance Ranged Ranged (firearms, bows, crossbows, throwing), balance, tactics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants