here is my code, I want to implement a function to detect if a player is visible to another player.
Code:
bool is_visible_to(int client, int target)
{
float self_pos[3];
float target_pos[3];
float look_at[3];
float vec_angles[3];
GetClientEyePosition(client, self_pos);
GetClientEyePosition(target, target_pos);
MakeVectorFromPoints(self_pos, target_pos, look_at);
GetVectorAngles(look_at, vec_angles);
Handle trace = TR_TraceRayFilterEx(self_pos, vec_angles, MASK_VISIBLE, RayType_Infinite, trace_entity_filter, target);
bool result = TR_DidHit(trace) && TR_GetEntityIndex(trace) == target;
delete trace;
return result;
}
bool trace_entity_filter(int entity, int contentsMask, any data)
{
if(entity == data)
{
return true;
}
if(entity > 0 && entity <= MaxClients)
{
return false;
}
char class_name[PLATFORM_MAX_PATH];
GetEntityClassname(entity, class_name, sizeof(class_name));
return strcmp(class_name, "infected") != 0 && strcmp(class_name, "witch") != 0 && strncmp(class_name, "prop_dynamic", 12) != 0 && strncmp(class_name, "func_breakable", 14) != 0;
}
I found that issue, the glass(map c11m1_greenhouse, classname "prop_physics", image attached below) did hit the trace, but there is no survivor glow, so it's "visible" but my function return false. how can I filter something such like this?
Note:
I tried L4D2_IsVisibleToPlayer in left4dhooks, it can't meet my needs cause when someone are not alive and spectating another one, the "eye position" not follow.