How to check for visibility, 101


(jaybird) #1

I’m not exactly sure how to check for visibility of a player. I am trying to check if a player is visible or not in the current screen from a spectator’s point of view (I could guess it doesn’t matter if they are spectator or not, though). I need to be able to tell whether the player is fully visible, or if they are hidden by a blocking object such as a wall, for instance.

I am working client side on this. Any tips?


(zinx) #2

The only semi-reliable method without some amazing engine hacks (which are illegal) is tracing to a bunch of points on the player, and even then it’s still possible you’ll see someone as being non-visible. Also, that method is extremely slow. Sorry :x


(jaybird) #3

Yeh, I figured it would be a little tough (there was no obvious method I could find in the code already).

Perhaps you might give me a little insight. The reason I’m doing this is to get something close to what ETPro has in Shoutcaster ability. I know it won’t be of too much use in my mod (as it is aimed at the pub community), but I have gotten several requests for it so I thought I’d give it a shot. In ETPro, when a player is no longer visible, the name above their heads fades out. I already have the names displaying correctly over their head (by using one of the paint text functions), and I’d like to not display it if they are blocked from visibility. The way I figured that this was accomplished was to check whether the player is visible each frame, and if not, set a local time variable for that player and fade off of it. Am I going about this the right way?

I think this would be a bit easier if I had a better idea of how the traces work. I haven’t really been able to find much material around that half-way explains it.


(bani) #4

etpro traces to cent->lerpOrigin for nametags. here’s a function to do the trace you want:

//is point visible from camera viewpoint?
qboolean PointVisible( vec3_t point ) {
        trace_t trace;

        CG_Trace_World( &trace, cg.refdef_current->vieworg, NULL, NULL, point, 0, MASK_SOLID );

        if ( trace.fraction != 1.0 ) {
                return qfalse;
        }
        return qtrue;
}

(jaybird) #5

Well that was simple enough.

Thanks Bani!