Skip to content

Commit

Permalink
increase weapon prediction entity match range
Browse files Browse the repository at this point in the history
Fix potential issues with duplicate weapon events when firing weapons from very fast moving platforms.
  • Loading branch information
Chomenor committed Sep 17, 2023
1 parent 89eac84 commit 2a24428
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions code/cgame/cg_predict_weapons.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,36 @@ static qboolean CG_WeaponPredict_CanStickGrenade( int entityNum ) {
return qtrue;
}

/*
================
CG_WeaponPredict_EntitySearchRange
Increase allowed match range for predicted entities and events when moving fast or standing on a
fast mover. This range is just used as a sanity check so it's fine if the values are very rough.
================
*/
static float CG_WeaponPredict_EntitySearchRange( void ) {
int groundEntityNum = cg.predictedPlayerState.groundEntityNum;
float range = 250.0f;

float speed = VectorLength( cg.predictedPlayerState.velocity ) / 8.0f;
if ( speed > range ) {
range = speed;
}

if ( groundEntityNum > 0 && groundEntityNum <= ENTITYNUM_MAX_NORMAL ) {
centity_t *cent = &cg_entities[groundEntityNum];
if ( cent->currentState.eType == ET_MOVER ) {
float speed = VectorLength( cent->currentState.pos.trDelta );
if ( speed > range ) {
range = speed;
}
}
}

return range;
}

/*
================
CG_WeaponPredict_FindMatchingEntity
Expand Down Expand Up @@ -627,7 +657,7 @@ static float CG_WeaponPredict_ComparePredictedEvent( const centity_t *cent, void
float origin_delta = ORIGIN2_BASED_EVENT( event ) ? Distance( es->origin2, predicted->origin2 ) :
Distance( es->pos.trBase, predicted->origin );

if ( origin_delta < 250.0f ) {
if ( origin_delta < CG_WeaponPredict_EntitySearchRange() ) {
return origin_delta;
}
}
Expand Down Expand Up @@ -1089,7 +1119,7 @@ static float CG_WeaponPredict_ComparePredictedMissile( const centity_t *cent, vo
dot = 0.5f;
}

if ( deltaOrigin < 250.0f ) {
if ( deltaOrigin < CG_WeaponPredict_EntitySearchRange() ) {
// take dot product into account even if deltaOrigin is 0
return deltaOrigin / dot + ( 10.0f - dot );
}
Expand Down

0 comments on commit 2a24428

Please sign in to comment.