Reasons leading me to do this exercise utilizing Unity's Data-Oriented Technology Stack (DOTS), i.e. Entity–Component–System (ECS), Burst and Jobs:
- High consistent frame rate being of essence in virtual reality.
- Demonstrating code that would perform at a higher scale.
- Immanent curiosity to experiment with new technology.
- Urge to deepen my understanding of Data-Oriented Design and especially Entity–Component–System.
Here, I have not shown an implementation that would scale well. It has:
- Brute-force checking all against all; O(n²).
- Circular collision shapes for everything.
For large numbers (hundreds, thousands) of objects of various shapes, I would implement:
- Broad phase; quickly sort out objects far apart that cannot collide.
- Spatial partitioning; uniform grid with spatial hashing; O(n) on average.
- Simplified bounding shapes; axis-aligned bounding boxes (AABB).
- Narrow phase; check objects close enough to possibly collide.
- More accurate collision shapes; circular, rectangular, polygonal.