Game Development Community

List of Visible Objects?

by Lally Singh · in Torque Game Engine · 03/25/2007 (6:02 pm) · 5 replies

Hey everyone, what's the best way to get a list of what's visible right now?

I really just need a list of visible players, like literally the ones the current player can see right now. If they're hidden behind a building, behind me, etc., I don't want them.

Best idea so far is to start scanning the SceneObjects manually, and hoping not to take too long in manually transforming them into viewport coordinates that I can test, but that doesn't take care of occluded objects. Still, if there was a way to get a list of what's on the screen, even if it's hidden behind a building, I'd take that too.

Thanks in advance for any help!

-ls

#1
03/25/2007 (6:07 pm)
I don't know if there's an official way to do this, but the way I'd do it is to perform a raycast to each player. If there's something in the way, then the raycast will return a 0. The only problem with that is that your player might be behind a tree, so that it is still visible to the person playing, but the raycast will hit the tree and return a 0. Still, it' a start.

--Amr
#2
03/25/2007 (6:27 pm)
You might try going through "MissionCleanup" which is just a SimGroup, but it might be easier if you create a new simSet, and put code in the onAdd function to add all players to that set, then just find the positions of everything in the set.
#3
03/25/2007 (9:02 pm)
There are a couple of ways to do this. If you want to do this in game using scripts you can loop through the clients using the following code (The following code assumes you are looking for player characters, controlled by a client. If you are wanting to get a general player object list you could try using the InitContainerRadiusSearch operation...

%count = ClientGroup.getCount(); //The number of clients to check
for(%i=0; %i < %count; %i++)
{
    // DO YOUR CHECKS
}

Now that you have your method for looping through your clients you need to perform your checks... the very first check you would want to do is just to make sure before you do any fancy calculations or ray traces the client is within your maximum distance. So to do this you could use a check like below.

%targetClient = ClientGroup.getobject(%i);
%distance = vectorDist(%targetClient.player.getPosition(), %obj.getPosition()); // %obj would be your player
if (%distance < $maxDistance)
{
    // DO YOUR NEXT CHECK
}

Now the next check is going to be sure that the target player is in your field of vision. There are a couple examples of this on the GG site somewhere... I couldn't find my example right now..

And finally the last check would be to use a ray cast to the player to ensure it is not blocked by terrain, interiors, or static shapes.
#4
03/25/2007 (10:59 pm)
I'll add my flavour - i'd take a look at what's going on in the GuiShapeNameHud,
which makes its own calculations for which players are actually on screen,
and store those results in the GuiShapeNameHud.
ie a list of the visible player objects.
the additional computation should be about nil.

edit: .. should be about exactly nil, and also has the benefit of matching the existing impression of who's on screen given by whether or not their player name is visible. let me know if you want more details.
#5
03/25/2007 (11:20 pm)
I'm thinking of doing something along the lines of what you need for my RPG game. Pretty much a view "trigger" for anything that's identifiable (characters, objects, terrain, etc.) in plain sight of the player (or AI). I'm still a bit off from working on it though.

Looks like you've got a good solution for your problem. :)
- Ronixus