-
I'm pretty new to ECS and just learned about entt and want to try to implement it in some game engine code I wrote. I tried to google on how to deal with collision detection in an ECS but couldn't really find a good article about it. A lot of solutions seem to iterate over all entities and just check all bounds (talking about 2D here), which seems really stupid to me. What I'm thinking I should deal with is:
So my question is, how can you use entt to only get objects in close proximity? If possible? Pretty much my question is, how would you generally work with collision detection in entt? My question is mostly about 2D now but I think the solution would work for both 2D and 3D all the same. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Using a component based design doesn't mean that you've to do everything in terms of entities and components. In this case you want to perform a spatial lookup and a linear array in which things are moved to optimize linear accesses isn't the best choice. EnTT allows to create custom pools with which you can structure your data to easy the job, but that's an implementation detail and something pretty advanced. |
Beta Was this translation helpful? Give feedback.
-
I hope @skypjack 's answer was to your satisfaction. I still would like to give you some pointers...: |
Beta Was this translation helpful? Give feedback.
-
Thank you for your responses, it helped me to give some perspective on how to implement this. I've been looking into Box2D and will be implementing that together with entt. |
Beta Was this translation helpful? Give feedback.
Using a component based design doesn't mean that you've to do everything in terms of entities and components. In this case you want to perform a spatial lookup and a linear array in which things are moved to optimize linear accesses isn't the best choice. EnTT allows to create custom pools with which you can structure your data to easy the job, but that's an implementation detail and something pretty advanced.
In general, I'd suggest to still use something like a grid based lookup, a quad tree or any other approach suitable for a broad phase and the algorithm that fits best with your requirements (AABB or whatever) for the narrow phase. You can put entities in these data structures and us…