I am trying to make func_static entities toggle existance depending on the player’s distance if the flag “start_invis” is checked on the entity. This is the only thing remaining to complete my rain effects (would be used to fade rain impacts to avoid huge framerate loss), and I don’t think my C experience level is enough. Please if someone knows how to make it happen let me know, it’s just about the only thing that remains in my todo list. This is what I’ve tried to do, with no luck:
void SP_func_static( gentity_t *ent ) {
float distance, values ;
gentity_t *player;
if ( ent->model2 ) {
ent->s.modelindex2 = G_ModelIndex( ent->model2 );
}
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
//ent->use = Use_Static;
player = AICast_FindEntityForName( "player" );
if ( ent->spawnflags & 1 ) {
if (player)
{
values = (player -> r.currentOrigin[0]* ent->r.currentOrigin [0]) + (player -> r.currentOrigin[1]* ent->r.currentOrigin [1]) + (player -> r.currentOrigin[2]* ent->r.currentOrigin [2]);
distance = sqrt (values);
if (distance > 6000)
{
trap_UnlinkEntity( ent );
}
else
{
trap_LinkEntity (ent);
}
}
}
Probably this is not the correct way to make an entity appear or disappear. What am I doing wrong?