2D mesh modeling of water / liquid (based on platform tiles)

I have a net game (platformer) where I based everything on tiles. I have solid and liquid tiles. I am trying to find a good way to make water tiles simulate water roughly.

I currently have the current system: When a water tile is added above another water tile, it adds 1 to the water plate below. A number indicates pressure.

Here's what it looks like at the moment:

[0] <- This water tile has 0 in pressure. [1] <- This water tile has 1 in pressure. 

If I add another water tile next to the bottom, it will search on the left, on the right and above if there are any water cannons and inherits the greatest pressure around it.

Example:

 [0] [1][1] 

And here is a great example after adding a few tiles:

 [0][0] [1][1][1][1] [2][2][2][2][2] 

Then I make each water-jet slab that has a pressure equal to or greater than 1, try to move left / right, if there is free space, then set the pressure to 0 and check if it can inherit the pressure around it from neighboring reservoirs, if there are by any.

This system works very well, unless tiles are removed from the water from above.

If I remove the top water tiles from the last example:

 [1][1][1][1] [2][2][2][2][2] 

Then we have the top row with pressure 1, now it should be 0, and the bottom row should have 1.

Is there a smarter system that I can implement to make this more correct?

The following are limitations:

Each tile can only be checked by its neighbors. A tile can have any function. A tile can have any variable for storing data.

Can you guys create a better system that works better than mine?

A typical test case:

 [] [] should become [][] [] [] [] should become [][][] [] [][][] should become [][][][] 

Assuming the game has been running for a while.

Any suggestions would be more than welcome!

+6
simulation grid tiles
source share
2 answers

Perhaps you could forget about pressures (since you don't actually use them as pressure) and just use bool tryMove or something like that.

Each simulation step should be divided into two sub-steps:

The first cycle in the tile:

  • If the free space is lower, set tryMove to true, complete this snippet.
  • If you have the tile above, set tryMove to true yet, set tryMove to false.
  • If any neighbor is trying to move, set tryMove to true.

The second cycle in the tile:

  • If an attempt to move and free space below is free, move the tiles down, set tryMove to false, the finish tile.
  • If you are trying to move and can move sideways (free space on the left or right) set neighbors tryMove as false, move it, set this tryMove as false, the finish tile.

I think this should solve your problem.

0
source share

If you have the resources to support it, I recommend a recursive function that tries to click tiles on the top left and right. If the function finds another plate below, it may try to push the plate in both directions. The best method would be to start a step left and right, one plate at a time. If he continues to find tiles, then he continues to move. In the end, it will either end with tiles to check (ends against the wall) or find a plumbing with free space to move. After several iterations, the water should go outside and make room for water to fall.

Let me repeat the left and then the correct nature of recursion. In fact, as soon as the function moves to the base water level, it should start choosing tiles for water, alternating left and right. Therefore, first check the stove right on the left, then right on the right, then two on the left, then two on the right, etc. If he finds an air tile, he will have to move the nearest water tile. If he finds something else (usually a wall), he must abandon this side. After he surrendered on both sides, you should consider other behaviors, for example, the topmost water that accidentally moves along the surface.

If you really want the behavior to look natural, I highly recommend a random variable that decides whether it checks first left or right. Otherwise, you are likely to come across unusually regular repeating patterns.

0
source share

All Articles