Querying Entities Within a Proximity of Another

  • Thread starter Thread starter Sarron
  • Start date Start date
S

Sarron

Guest
Hello again. =)

In a nutshell, my goal here is to have objects change their state depending on what entities are close to them within some range (or, even better, within some arbitrary volume around them) and based upon the state of those entities.

Obviously, there are existing I/Os for Touch and for entering or exiting a trigger area, but what if I want to find out who's near entity A in a think method of that entity and respond to the state of those entities?

First, is it possible to find out (directly) which entities are within an arbitrary volume around an entity during a Think? Second, could I then query data about that entity directly from it as I go through a list of them?

What it comes down to is the question of whether there an easy or straightforwardway to do this, or would it likely involve something complex?

An example of a complex solution would be having every entity I care about register itself, in a sense, as being in each volume it's within during it's own think. Each entity would also register the pertainent information about it at that time. Then, an entity could just check with that registry to find out about the entities around it. However, this is obviously a rather complex, and possibly CPU and network taxing way to do things.

Thanks for any input/insight anyone could offer. =)
 
Check out the function:

CBaseEntity *CGlobalEntityList::FindEntityInSphere( CBaseEntity *pStartEntity, const Vector &vecCenter, float flRadius )

It's in the file: EntityList.cpp, Around line: 713.

That will give you the entities around you.
 
Perfect. Thanks! =)

I'll probably post any other directly related issues I may find or solve in this thread as well.
 
Some findings...

Okay, so I've looked at FindEntityInSphere(...) and how it's used in HL2.

In the all the uses I found, the first argument (CBaseEntity *pStartEntity) is given as a null CBaseEntity pointer, which is created just before a while loop in which the non-nullity of the return from the call (which is itself a CBaseEntity pointer).

Then, any amount of craziness can be done relating to the returned entity.

The following line intrigues me:
Code:
const CEntInfo *pInfo = pStartEntity ? GetEntInfoPtr( pStartEntity->GetRefEHandle() )->m_pNext : FirstEntInfo();

Apparently, each entity carries a reference to the next entity in the global list of entities. In other words, the list of entities is a doubly-linked list. Or am I misinterpretting this?

So by setting the same CBaseEntity pointer to the value of the "FindEntityInSphere" call whose first argument was the pointer itself, we loop through all the entities in the sphere, stopping when we are given a null entity pointer.

That's all I've gathered so far.

(Is there a place in the HL2World Wiki for speculation and commentary on SDK calls like this?)
 
Arbitary Spaces...

So now I'm thinking about what we'd do if we wanted to associate an arbitrary volume for certain entities as their "checking space". Essentially, it seems like we would need to associate a set of simple geometric spaces (boxes and spheres, for examples) that make up the checking space for an entity.

How would we create those spaces, though? Another entity, as created in Hammer, would seem to be the obvious answer.

In fact, this answer seems too obvious. Am I looking to create something that's already there? This idea of a "checking space", as I'm calling it, seems VERY similar to bounding boxes and the associated checks.

Perhaps, then, we could implement checking spaces by using the same mechanisms by which bounding boxes are checked for collision detection?

Any thoughts on this?
 
Back
Top