legion icon indicating copy to clipboard operation
legion copied to clipboard

How to query for "entities on screen," or "in range entities"?

Open canadaduane opened this issue 4 years ago • 3 comments

Looking for advice here. Have others dealt with the issue of introspecting whats going on on the screen, or querying for "in range entities"?

For example, how would I get a list of the entities that are visible on the screen right now, with all components, and show them in one nice imgui window (think of a mini-map)?

A similar problem is how to iterate over all enemies within range of the player's spell. Would you cache the distance-to-player somehow? Or is there another way to query for entities in range of another entity?

canadaduane avatar Jan 26 '20 19:01 canadaduane

You can use an octree to cache Entitys which are in a given region, then use the Entitys retrieved from the octree for random access.

This isn't really something that falls under Legion's scope; it's more of a general gamedev problem.

caelunshun avatar Jan 26 '20 19:01 caelunshun

Thank you, this is very helpful.

I wonder if it would be good to give examples of solutions in Legion that are "common problems" like this? It would certainly make adoption for newcomers easier, and signal that Legion has considered a variety of practical cases (and is going the extra mile to help people like me, building a game atop Legion but still shaky on some things).

canadaduane avatar Jan 26 '20 19:01 canadaduane

Hello there, This is exactly what i'm trying to achieve with the rstar crate. I have all the tree setup being done already and the ability to get an iterator of entities inside the frustrum.

I'm now trying to get a custom filter to add to the query, but the tree is a resource, which I can't find a way to read-only access at filter time. Is there something I'm missing ?

IcanDivideBy0 avatar Mar 20 '20 18:03 IcanDivideBy0