Game Development Community

Players visibility test

by Julien Millet · in Torque Game Engine · 08/13/2005 (10:23 am) · 6 replies

I've seen complex questions and complex answers, and I think it may be good to have a thread with a simple answer.

It's server side, I have enemies, and I just need to do a test, kindof enemy.isVisible()

How do I do ?

#1
08/13/2005 (1:20 pm)
It's a complex question. Depending on what you want there are a lot of ways to do this. Can you tolerate false positives or false negatives? How many times a second do you need to do it? What are the properties of the scene? What graphics card/CPU are you targeting, if any? (I'm guessing none if it's server side.)

The usual way would be to cast a ray or three between the eye position and the target object and see what you hit. If you hit the object it's visible; if you don't it's not.
#2
08/13/2005 (1:48 pm)
Or you could just use the angle between their positions and the player's eye vector, and then use a FOV angle comparison. So you could say that an an enemy is visible (or vice versa) by checking the angle it makes. You could do this based on the viewing frustrum as well. Look in the TGE for something that gives you a clue to when an enemy isn't drawn in the scene because it's being occluded, because otherwise it's included ;).

- Eric
#3
08/15/2005 (1:25 am)
If we want to keep things simple and working most of the time, I think it's better to check if enemy is drawn or not.
I still haven't managed how to do this, but I'll continue my searches on the forum.
#4
08/15/2005 (1:41 am)
You mean, drawn at all (which will return true if it's behind a pillar or wall) or actually visible (which basically asks, are any pixels drawn for a given shape)? The former is easy, the latter more complex.
#5
08/15/2005 (1:51 am)
The former.
#6
08/15/2005 (10:13 am)
I wrote a spiffy little algorithm for some AI sight. I can't give you the code, but I can describe what it did. It first determines if the object it is looking for is within a specified angle of the AI's eye point. Then it checks against a specified distance (which I lowered depending on the view angle to simulate peripheral vision). Finally, it casts rays to each of the objects 8 bounding box verticies, as well as the bounding box's center to check for obstructions. If there is at least one ray with no obstructions, and we are within the specified limits, then at least some of the object is visible.

Is that along the lines of what you need to do?