Making Corpses Disappear

If you have a number of NPCs in a level you will find that having their corpses lying around can adversely affect the framerate of the game. This tutorial will show the source code changes necessary to make their dead bodies sink into the ground after a specified period of time.

For this tutorial we will have the corpses lie around the level for 6.5 seconds before starting to sink and allow 3 seconds for them to sink out of sight before removing them altogether.

In g_npc.c right before the function DieNPC about line 97 add :

#define CORPSEWAIT 6500 // 6.5 sec wait before start of sinking
#define SINKTIME 3000 // 3 sec to sink
void NPCBodySink( gentity_t *ent ) {
if ( level.time - ent->timestamp > (CORPSEWAIT + SINKTIME) ) {
G_FreeEntity( ent );
return;
}
ent->nextthink = level.time + 100;
ent->s.pos.trBase[2] -= 1;
}

In g_npc.c in function DieNPC about line 145 add :

	G_UseTargets(self,attacker);

self->nextthink = level.time + CORPSEWAIT;
self->think = NPCBodySink;
self->timestamp = level.time;
self->physicsObject = qtrue;
self->physicsBounce = 0;

}

In g_npc.c in function G_RunNPC about line 473 add :

	npc=&ent->ns;

if (npc->state==NPC_ST_DEAD)
{
if(ent->nextthink<level.time)
{
ent->think(ent);
return;
}
}

ucmd.serverTime=level.time;
ucmd.angles[0]=ucmd.angles[1]=ucmd.angles[2]=0;


A simple fix for having all those bodies lying around slowing down game play.

                                  
Return to Home Page