Skip to content

Commit 774d842

Browse files
committed
feat: make gibs tumble (rotate)
1 parent 436e930 commit 774d842

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

code/cgame/cg_cvar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CG_CVAR( cg_gibsInheritPlayerVelocity, "cg_gibsInheritPlayerVelocity", "1.0", CV
2323
CG_CVAR( cg_gibsExtraRandomVelocity, "cg_gibsExtraRandomVelocity", "250", CVAR_ARCHIVE )
2424
CG_CVAR( cg_gibsExtraVerticalVelocity, "cg_gibsExtraVerticalVelocity", "100", CVAR_ARCHIVE )
2525
CG_CVAR( cg_gibsBounceFactor, "cg_gibsBounceFactor", "0.4", CVAR_ARCHIVE )
26+
CG_CVAR( cg_gibsRotationFactor, "cg_gibsRotationFactor", "1.0", CVAR_ARCHIVE )
2627
CG_CVAR( cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE )
2728
CG_CVAR( cg_drawStatus, "cg_drawStatus", "1", CVAR_ARCHIVE )
2829
CG_CVAR( cg_drawTimer, "cg_drawTimer", "0", CVAR_ARCHIVE )

code/cgame/cg_effects.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)