For about 2 years, I have been making small stupid games. Each game taught me a lot and I’m really enjoying the fact that I can make games. However, I’m bumping a lot of times into the best way to check collision with in game entities. The most simplistic approach would be:
for (Entity e: level.getEntities()) {
if (e.collidesWith(this)) {
// Do stuff
}
}
Now, if we would have a system where every entity is checking collision with other entities, the amount of loops will explode exponentially and performance would crash. Someone told me the best solution to this is by having a binary search tree to only list entities that CAN collide with the current entity. I’ve been studying this thing, but can’t really get the hang of it.
- What’s the best way to take care of this?
- Could a binary search tree fix this?