legion
legion copied to clipboard
How to query for "entities on screen," or "in range entities"?
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?
You can use an octree to cache Entity
s which are in a given region, then use the Entity
s 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.
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).
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 ?