Hello I need a water mechanic like terraria!


Hello everyone. I need a water mechanic—or rather, water physics—like the one in *Terraria*, and I’m wondering how to implement this in GDevelop. I’d love to hear your ideas. I tried the “marching squares” approach, but it didn’t turn out quite right; the water didn’t behave fluidly. I also tried a “dynamic water” mechanic, but that didn’t result in actual physics-based behavior. Basically, here is what I’m trying to achieve:
Imagine there is a body of water; if I break the blocks beneath it, the water should flow sideways or downwards as I break the adjacent blocks. In short, I want to replicate the exact water mechanics found in *Terraria*. Could you offer some ideas or help me out? I’m attaching some relevant images.

i know this isnt the answer you or anyone is looking for, but i have NO idea man

Never played terraria so i have no idea how water flows there
But you could totally when block HP is 0 or hit by something that would destroy it
Check if point at positon
Block.CentetX() Block.CenterY() - Block.Height()
Block.CentetX() Block.CenterY() + Block.Height()
Block.CentetX() - Block.Width() Block.CenterY()
Block.CentetX() + Block.Width() Block.CenterY()

Is inside water
Of so then you could store in variable which point was in water
Spawn some object at its place and fake flow of water into Center of bock position which you should also store in variable
And then delete block after you get all info you need

I want the water to flow, whether the blocks break or not, just flow across the ground, like a 2D version of Minecraft.

the reason i was so vauge in my response, is because there isnt enough information to help you. Because the implementation of water heavily depends on your implementation of blocks, and for that i highly suggest tilemaps.

Not sure if this is what your looking for but you could make each drop of water a 2d object like how this game works.


Well, it’s not exactly like that, actually. The water needs to flow into itself—there has to be a proper flow of water. Just think of it like 2D Minecraft; the water mechanics will be strictly 2D.

Oh, so unlike terraria, and more like minecraft water..?

Minecraft Water relies on Source Blocks which will keep it flowing but not flowing infinitely, which also leads to development of Infinite Water Sources

Terraria Water is more realistic and if you were to dig a hole straight to Hell in one of the Oceans, all that water would effectively drain into Hell and evaporate meaning without a certain tool (Bottomless Bucket of Water) you’d essentially have the ability to transport water, let it drain down cliffs or hills, or create waterfalls

One relies on Physics, the other is… I guess just uhh…. Idk Minecraft is weird lol

minecraft’s water feels like a placeholder so lakes could exist

I did this today …after much faff and bother!

water sim

which could possibly be turned into an extension unless theres already something similar. The events are currently complicated and need optimising. Its using simple rules instead of physics and point inside object tests.
It might also be worth (if you can afford it) seeing what vegetato did in his terraria template.
Any terraria copy will already be using quite complicated events and so water logic needs to be really simple and well optimised, and i’m still not entirely sure that this is as yet!

Purely for my own curiosity I did a new version of the above but just using an array and so checking the array for 0,1 or 2 instead of point inside object checks etc. This was actually much easier than with objects with no messing about with not referring to self etc and runs much better.
This is however probably less adaptable to other projects as you’d need an array based cellular world

its kind of fun to play about with and the algorithm does generate air bubbles …which is kind of cool!

i dont wanna ask for too much, but can this be implemented into tilemap?

ive never used tilemaps, but i guess so. Do you mean auto tiling though?

no thats not what im talking about? im talking about the water being a tile in a tilemap

id have to completely rework it. At the moment the water sprite object relates to the world array through its id and the variables that relate to movement are stored in the sprite object. If there’s one tilemap object id need to store all information about the water in the world array then scan the local world array area in a repeat event and tell the tilemap what to tile where. Its doable but i don’t fancy doing it at the moment.
I added a basic autotile algorithm that changes the ani based on neighbouring cells

might add a water pressure algorithm next

I did manage to do it with 1 tilemap object
This reads and writes the local area of the world array (not every frame). There’s two arrays, a before and an after. There’s no collision checks or point inside obj or object variables its purely based on whether world[runlocalcheck] is 0,1 or 2. 1 being wall and 2 being water. I found that you need to check both the before and after array b4 moving something. I haven’t done an autotile algorithm here yet. I might try doing conways game of life later as this would be useful for that sort of thing. Im an artist in the real world not a programmer but im finding myself drawn to the programming side for some reason!
The repeat event to process the world is 64*40 and you can see the fps dip to 58 when that happens
water sim2

i was very close to being able to use this, but unfortunately, i cant have it use an array…oh well

if you didnt want to use an array since the tilemap is an array you could possibly do what I did above but using two tilemaps and at the start of the repeat event that reads and writes create a new tilemap and read from the old one and write to the new one then delete the old.

huh…so, this requires a previous state?