-
Hi, I've just started with DefaultECS and ECS in general. I'm trying to figure out how to implement a collision system. I wish to implement a simple spatial grid and store the entities on that grid based on their 2d position (like this one : https://gameprogrammingpatterns.com/spatial-partition.html) In your documentation you state that I should avoid storing entities, so I have difficulties to figure out how to implement this kind of system. Have you a way to acheive that ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Not the owner of this repo, but i also use default ECS and a quadtree. Then i basically grapped the first best quadtree library and put thos entities by their unique id in it. Then you can query nearby entities, receive their unique ids, resolve them to get the real entity references. |
Beta Was this translation helpful? Give feedback.
-
Hey, the main reason I discourage from storing entities in your own container is because you would then be responsible to keep it up to date with the entities state (were they disposed? did their composition changed? ...) but if you know what you are doing it is completely valid to do so. |
Beta Was this translation helpful? Give feedback.
-
Hi genaray & Doraku, Thanks a lot, your solutions seems to fit what I want to do. |
Beta Was this translation helpful? Give feedback.
Hey, the main reason I discourage from storing entities in your own container is because you would then be responsible to keep it up to date with the entities state (were they disposed? did their composition changed? ...) but if you know what you are doing it is completely valid to do so.
There is an existing container built in that could help you to achieve a spacial grid, the
EntityMultiMap<>
. I actually use just that in the boids sample. I use aGridId
component that is recalculated when the entities move and when the multimap is notified of those changes it move entities around in what is basically aDictionary<GridId, Entity[]>
so I can access neighbors in O(1) (and as it is a native…