Skip to content

Conversation

@wgetJane
Copy link
Contributor

@wgetJane wgetJane commented Oct 30, 2025

Description

fixes ValveSoftware/Source-1-Games/issues/5904

supersedes #634

alternative: #1593 (simpler solution)

this pr's solution:
- find point on the arrow's trajectory line that's closest to the hitbox centre
- from that trajectory point, find distance to closest point on the hitbox's surface
- no intersection tests (a lot cheaper)
image

solution in #1593 (cross product):
- from the arrow's impact point, raycast to hitbox origin
- from that raycast's intersection point, find perpendicular distance to arrow's trajectory line
image

solution in a4f7b4f (projection):
- finds point on the trajectory line that's closest to the hitbox origin
- from that trajectory point, raycast to hitbox origin (to get raycast distance)
image

original behaviour:
- shift arrow's impact point 16 units forward
- from that point, raycast to hitbox origin (to get raycast distance)
- this can easily give unintuitive results (frustrating to both the user and the victim)
- bug: hitboxes are treated as axis-aligned boxes rather than oriented boxes!!!
image

@wgetJane wgetJane changed the title [TF2] Improved huntsman arrow hitbox selection [TF2] Improved huntsman arrow hitbox selection (no raycast approach) Oct 30, 2025
@wgetJane
Copy link
Contributor Author

wgetJane commented Oct 30, 2025

some extra considerations:

// We struck the collision box of a player or a buildable object.
// Trace forward to see if we struck a hitbox.
CTraceFilterCollisionArrows filter( this, GetOwnerEntity() );
Vector start = GetAbsOrigin();
Vector vel = GetAbsVelocity();
trace_t tr;
UTIL_TraceLine( start, start + vel * gpGlobals->frametime, CONTENTS_HITBOX|CONTENTS_MONSTER|CONTENTS_SOLID, &filter, &tr );

i think start + vel * gpGlobals->frametime here is weird, like why is it even based on frametime?

the trace distance here would typically be around ~30 units, which could fall short

imo something like start + forward * 48 makes more sense, or maybe even longer (for giant targets)

---
another thing: using dot product instead of distance for selecting a hitbox

this would have similar results but would be slightly biased towards farther hitboxes
(because angular changes are less pronounced from farther away)

however, that might actually be desirable, because of how perspective works
(like how farther objects are closer to your crosshair when projected onto your 2d screen)

im not too sure though since it feels subjective, idk which makes more sense perceptually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TF2] Huntsman headshots are inconsistent depending on victim's world space orientation

1 participant