nocontrolco / elso

Electric Lightning Soccer Overdrive
GNU General Public License v3.0
0 stars 0 forks source link

Implement neighbors search for game entities #10

Open diasssavio opened 2 months ago

diasssavio commented 2 months ago

Following the likes of #1 & #2, we'll need a search mechanism to identify near elements that may interact/collide with one another.

For instance, to check which entities will add forces to the ball, we need to search near spatial elements. This way, we avoid iterating over all game entities, which can be quite costly, depending on the operations we need to perform for each entity.

A possibly good approach for that, is using spatial grid search. In this method, we discretize the game domain into fixed-size cells (e.g. 20 m² into a 10 x 10 grid w/ cells of 2m²). With that, we identify each game element cell[s] and only look for neighboring cells for possible collisions, instead of looking everywhere. As thinner is the grid mesh, more precise it'll be, with a memory drawback.