- Home /
Advice on lavaflow (minecraft like)
Hey people, I am currently working on minecraft like game. (Before you go sigh, not another one, been done before etc.) I am doing this just for my personal learning and wanting to get a hang of unity. I am a seasoned programmer, have been making games in XNA until recently when the support for it totally collapsed. So I decided to try Unity.
TL;DR I have procedural generated chunks that consist of a mesh, I am able to modify this mesh on the fly by "digging" and placing blocks. The mesh recalculates and adjust accordingly. Everything fine and dandy...
Now my question is I want to implement liquids into this. I half understand the concept of needing every X number of ticks (be they seconds / frames) I need to expand the flow in a specified direction. I can do that no problem as seen in the screenshot (green blocks are slime). I know how to propagate them, the only question I have is how to implement the said "ticks" i have tried several things but they all just instantly create the creep. I want the fluid to creep only each "tick".
How would I go about doing that? Throw me a bone.
PS: The creep is done in a co-routine.
Any help or advice would be much appreciated!
Thanks in advance
Answer by Bunny83 · Dec 15, 2013 at 02:56 PM
There are many ways to do something like that. How YOU implement it is of course up to you and your requirements :)
Minecraft has quite a few different type of ticks. In the case of water / lava they use scheduled ticks. So there's a scheduler which has a list of objects and for each object a corresponding time value. If the List is sorted by expiration time the scheduler just has to check if the first element in the list has expired and "tick" the object / block. You shouldn't use "relative" delays (like WaitForSeconds in coroutines) since at low performance the whole game runs slower. Such things are best bound to the game time.
To implement such a scheduler you can use a normal generic List of a "TickTask" class and implement an comparer function / interface so the items can be sorted by their "timestamp".
The TickTask class would only have two members:
timestamp
reference to a "tickable" object (an interface would make sense here)
If you want to schedule a tick you just add a new TickTask item to the list (with the desired timestamp) and sort the list. Since the list is always sorted the sorting shouldn't take much time (O(n)).
The scheduler now just checks each update if the first item's timestamp has expired. Then it removes the first item, ticks the object and checks the next one.
Answer by Toggy11 · Jan 09, 2014 at 08:13 PM
Maybe I'm a bit late but, you could make a timer that when activated runs a function then that function checks at one block above, below, left and right. Then if a place is free create a water block at that posistion.