Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Voxel water like minecraft ?

Discussion in 'Scripting' started by Endzone, Jul 27, 2015.

  1. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    hello, i have started a project which uses Voxels "cubes" similar to minecraft although the time has come where i need water ... i have searched for ages to find evan a tutorial on this topic but no one has one ..
    the kind of water im trying to create is as seen hear :

    from resent research ive found that many people used Cellular Automata but to be honest i have absoloutly no idea how to implement that into "water" if anyone would like to give me a hand with trying to create this or evan just give me some helpfull tips please feel free because i have no idea how im going to re create the water as seen in that video .. :(
    - Thanks ..
     
  2. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839
  3. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hey thanks for the reply :) i did infact check these out a while back but after the tutorial was over i kinda got lost and was unsure of where abouts to go from the way the water was done Thanks that link was fairly helpfull :)
     
  4. PropositionOne

    PropositionOne

    Joined:
    Jul 25, 2015
    Posts:
    13
    Minecraft only updates water blocks if something changes. One of the optimizations of Minecraft is there is no such thing as limited quantities of water (unlike, say, StarBound or Terraria where falling liquid drains the entire pool).

    Say you have a block of water with blocks all around it. Now you remove one of those blocks. Minecraft then sends an "update" event to the blocks around the block that was removed. When the water receives the "update" event, it checks the surrounding blocks for air. If it finds air, it creates the first section of a waterfall in the air pocket. The new waterfall block then registers for an update after a small delay. After the delay, the waterfall block receives an update. It checks all the blocks around it. It finds an airpocket below itself and then creates a waterfall block below itself. The new waterfall block then registers for an update after a small delay...

    and so on and so on.

    What you want to do is have limited amounts of water which is a much more intensive process than Minecraft. Updating one block requires it to "flood fill" check every block connected to the body of water to adjust the water level.
     
    Last edited: Jul 27, 2015
    lordofduct likes this.
  5. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    O
    Ohh i see what you just Explained to me sounds Alot better ... Thanks for the Great Response i might just try this out and see if i can acomplish it or not! .. Thanks again That was Extremely Helpfull!
     
  6. JotaRata

    JotaRata

    Joined:
    Dec 8, 2014
    Posts:
    61
    I know this is an old thread. As @PropositionOne said, you could use some kind of raycast system, which checks the block surrounding water in five directions (left, right, back, forw, down) you shouldn't check the up direction unless your water climbs up.
    I wouldn't put that sort of function inside the Update() method, instead i would call it using events.
    So if your terrain (I assume is procedurally generated) is modificated, it should call an event on every chunk saying thta the water blocks should check their surroundings, if a air block is found then use coroutines or Invoke(time) to check again, and again..
    Also I would use some kind of mesh generator script, because instanciating 10000+ cubes is quite expensive
    (i'd see this video:
    which explains how to make a voxel mesh)
    aaannd, dont forget abouts shaders, they literally can do miracles, idk put some refraction on it and it should look cool
    if you do, share some screenshots i'd really like to see a working water system.
    sorry for my english haha