let’s assume I have 100 small sphere triggers, and one of them is the player, can I get the closest and the one that I can see with raycast, without ray colliding with map/terrain, loop over 100 is expensive, I think about adding extra trigger to my player to check collision about other spheres before ray test, any better approach or is it enough ?
Really?
I bet it’s not.
well I am the player and let’s assume others spheres are bots, means that each one loop 100 times means 100 * 100
In that kind of situation where you have many tests for nearby objects it is a good idea to partition your space.
In essence you put your objects at a certain grid area to their own “list” (in actual reality it might not be a list, it could be a linked list or something else) and then only check for objects that are in the same grid cell and perhaps also the neighbor cells. This way you can already reduce the amount of tests a lot.
1 Like