I discovered a game named Noita and it made me want to try and replicate a similar system .
With a bit of research, I found a tutorial made by John Jackson and started to make it myself.
I followed the logic in the video, but made the code myself.
                                  
The system works with a Dictionnary<Vector2, Particle> that identifies every tile defined in the bounds, and a List of particles with every particle spawned.
Every update works in the following :
     - Loops through each particles moving in movingParticles
            - TryGetValue at the next particle position on the allTiles Dictionnary
                   - If empty, the particle goes to that tile
                   - If occupied, the particle tries to go on the bottom left or bottom right tile
                          - If still occupied, the particle
does not move and is removed from the movingParticles list
     - Finally every tile is checked, if there is a floating particle and looks if the tile below is empty
            - If empty, the particle is added in the movingParticles List
I optimised the movingParticles List because if not done it could be way too big for Unity to handle without lag.
This is done simply by checking in the main loop if the current particle is stuck and cannot move. If so, it is removed from that List at the very end via a buffer, to avoid any shift in the List while in the loop.
With the last step when each tile is checked, it prevents floating particles that are not in the movingParticles List to stay in the air.
                                  
For now there is only the sand that I recreated, and I found it very interesting.
I plan in the future to add water and gases on my free time and I will keep updating this page.
Back to Top