Creating a dynamic fluid system using terrain?

in the left, the red block moves down, as it moves down the terrain disappears. to the right, terrain reappears over the red block. would it be possible to make terrain behave this way?

I want to make a dynamic fluid system were fluid (preferably terrain/water) moves around models/parts and disappears while inside them. I could just make a large body of objects that disappear when another part is intersecting but this would take a lot of parts to fill in all the small crevices a model may have. and because terrain is made up of many little “Cells” the transition is a lot smoother and better looking.

3 Likes

It certainly is possible. It has been done before.

How? I don’t know. Seems pretty expensive to do though, assuming that terrain is constantly reconstructed based on a multitude of factors. You can see that its relatively performance heavy in the video itself too.

Dynamic fluid systems seem difficult to achieve and I probably wouldn’t chase after it without a strong enough use case for it. If anything, this is something I’d put a feature request to rather than try to do it in Lua.

2 Likes

Actually Terrain isn’t made up of that tiny cells. They’re about 4x4x4 studs, but visually they’re a lot smoother because Roblox adds some visual flair. You can see this really well with the brick texture, which is always cube shaped in 4x4x4 cubes.

Still, I gave it a try and this is what I got:

As you can see, there are big gaps where the part doesn’t align with the grid.

You can play around with the place file (23.2 KB) if you want. I don’t think there’s a way to get better resolution.

what about rendiering and not rendering a part? for example lets say I Have a 10x10x10 part intersecting with a 20x1x20 part. could we have the 20x1x20 part only be seen on the outside of the 10x10x10 part while also having it disappear when viewed on the inside? using glass for this didnt seem to work so maybe theres another way to do this?

Hmm. I suppose it’s possible. You could use CSG, but I don’t think it would be performant enough to update every frame. If you limit the parts to always be axis aligned, it should be pretty simple to do your own “fake CSG”. This is interesting stuff, I might try to get it working later.

You can add and remove terrain via scripts at runtime, and it’s actually surprisingly fast. Resolution is somewhat limited due to voxel size, and this may not scale to lots of objects (you haven’t said how many). Before you even consider this, you should ask if it’s actually necessary. What is the real problem you are trying to solve? You can do things like disable swimming state, make water completely transparent on the client, counter buoyancy, etc… such that you can have something like a submarine underwater that is actually full of water on the server, the players just don’t see it or interact like they’re in water.

Then there is the more classic fake of just teleporting players into an underwater base or vehicle that is just somewhere else on the map, stationary, with water outside the windows.

I mention these hacks because in my experience, extensive runtime modification of large amounts of terrain can be bad for both server and client memory churn. Even studio crashes on me if I try to generate and erase large chunks of terrain too many times without restarting.

4 Likes