@@ -537,6 +537,11 @@ static void CG_LaunchGib( const vec3_t origin, const vec3_t angles,
537537 const vec3_t velocity , qhandle_t hModel ) {
538538 localEntity_t * le ;
539539 refEntity_t * re ;
540+ // `VectorLength` would be more precise, but this is faster
541+ // and good enough for randomness.
542+ float speedIsh = fabs (velocity [0 ]) + fabs (velocity [1 ]) + fabs (velocity [2 ]);
543+ int i ;
544+ int mainRotationAxis = rand () % 3 ;
540545
541546 le = CG_AllocLocalEntity ();
542547 re = & le -> refEntity ;
@@ -556,6 +561,26 @@ static void CG_LaunchGib( const vec3_t origin, const vec3_t angles,
556561
557562 le -> bounceFactor = cg_oldGibs .integer ? 0.6f : cg_gibsBounceFactor .value ;
558563
564+ if (!cg_oldGibs .integer ) {
565+ le -> leFlags = LEF_TUMBLE ;
566+ le -> angles .trType = TR_LINEAR ;
567+ le -> angles .trTime = cg .time ;
568+ VectorCopy ( angles , le -> angles .trBase );
569+ // Just a few degrees of randomness.
570+ le -> angles .trBase [PITCH ] += rand ()& 7 ;
571+ le -> angles .trBase [YAW ] += rand ()& 7 ;
572+ le -> angles .trBase [ROLL ] += rand ()& 7 ;
573+ // TODO the tumble speed should probably depend on damage instead,
574+ // or at least on random velocity.
575+ for ( i = 0 ; i < 3 ; i ++ ) {
576+ // The numbers are not based on science, but it looks like
577+ // having one axis be bigger than others makes rotation look natural.
578+ float axisMul = mainRotationAxis == i ? 1 : 0.25 ;
579+ le -> angles .trDelta [i ] = speedIsh * axisMul * 0.5 *
580+ cg_gibsRotationFactor .value * crandom ();
581+ }
582+ }
583+
559584 le -> leBounceSoundType = LEBS_BLOOD ;
560585 le -> leMarkType = LEMT_BLOOD ;
561586}
0 commit comments