- Home /
Grid based water system
I have been trying to create a grid based water system, like the one in minecraft. I am not creating a voxel game but a normal 3d game, does anybody have any ideas on where to start with this. It needs to be created at runtime too.
You need to explain in detail how the grid-based (I assume you mean voxel-based) water will be combined with the other (normal) terrain, and why you would want such a combination.
I would like to make river system for procedural terrains. I just assumed that making a grid based system would be easier.
$$anonymous$$akak
A river is just a ditch in the ground with flowing water inside, so I guess there's not much to it... If you can change the height of the terrain mesh at every vertex, then you can create the river (you only have to add a plane for the water).
So I could make a copy of the terrain mesh and move it -0.5 in the y axis and then make it my water material, then I could apply the new heightmap. Do you think this could work?
Next point on the list would be to make a shader which moves a texture downhill and faster the more steep it is.
I have no idea how your terrain mesh generation works so it's impossible for me to say if it will work. What you posted doesn't make sense to me, why would you make a copy of your terrain mesh? Why move it downward? why make it your water material? Water is flat so it should just be a plane or at least a flat mesh. Why apply the new (which?) heightmap?
I used this link there is a more upto date on alexSTV.com buyt that focuses on 3d where the link i sent you startes with 2d generation wich is closer to what you want as a start.
http://studentgamedev.blogspot.no/2013/08/unity-voxel-tutorial-part-1-generating.html
I have run into a slight problem and that is that my terrain is 2048*2048 which gives me around 4.100.000 vertices, and the limit is 65000 is there another way to clone the terrain mesh?
EDIT: I can barely make a 250x250 which is already way too low quality.
@Cherno What I wanted to do is to make a clone of the terrain mesh, but only the mesh and then lower it a little so it is a little lower than the terrain, then make a shader which makes it look like the texture is always going towards 0 on the y axis. So I would have a copy of the terrain that is lower and looks like water and then after creating a clone modify the heightmap to be lower based on some RigdeNoise.
Well, if you use Unity's built-in terrain system, then I can't help with that. Generally speaking, if the vertex count gets too high, the mesh is split into smaller chunks, but I don't know how Unity's terrain handles that.
The links i sent you creats a multiple chunk system with that even removes chunks that cannot be seen by the player if you look at the $$anonymous$$STV.com
That is what I tried to do, but I can't get it to work. Here is my code:
var river = new RidgeNoise(Seed);
river.OctaveCount = 1;
river.Frequency = 0.001f;
//hw is heightmap width
int ChunkWidth = 250;
int ChunkCount = (int)td.size.x / ChunkWidth;
for (int cx = 0; cx < ChunkCount; cx++)
{
for (int cy = 0; cy < ChunkCount; cy++)
{
GameObject water = new GameObject();
Vector3 p = new Vector3(cx * ChunkWidth, -1f, cy * ChunkWidth);
water.transform.position = p;
water.transform.localScale = Vector3.one * 0.975f;
water.AddComponent<$$anonymous$$eshRenderer>();
$$anonymous$$esh w = new $$anonymous$$esh();
$$anonymous$$eshFilter mf = water.AddComponent<$$anonymous$$eshFilter>();
List<Vector3> vertices = new List<Vector3>();
int[] triangles = new int[(ChunkWidth * ChunkWidth * 6)];
int x0 = (cx * ChunkWidth);
int y0 = (cy * ChunkWidth);
for (int x = 0; x < ChunkWidth; x++)
{
float aX = (x0 + x) / hw;
for (int y = 0; y < ChunkWidth; y++)
{
float aY = (y0 + y) / hw;
float v = $$anonymous$$athf.$$anonymous$$ax(0f, river.GetValue(x0 + x , y0 + y, 0f) - 0.99f) / 5.0f;
vertices.Add(new Vector3(x, $$anonymous$$athf.$$anonymous$$ax(0f, heightmap[(int)(aY), (int)(aX)]) * Terrain.activeTerrain.terrainData.size.y, y)); //This line is causing me trouble, it gives me a negative value for the heightmap, but I can't seem to figure out why.
heightmap[(int)(aY), (int)(aX)] -= v;
}
}
//$$anonymous$$ake the triangles
int t = 0;
for (int face = 0; face < (ChunkWidth - 1) * (ChunkWidth - 1); face++)
{
int i = face % (ChunkWidth - 1) + (face / (ChunkWidth - 1) * ChunkWidth);
triangles[t++] = i;
triangles[t++] = i + 1;
triangles[t++] = i + ChunkWidth;
triangles[t++] = i + 1;
triangles[t++] = i + ChunkWidth + 1;
triangles[t++] = i + ChunkWidth;
}
w.vertices = vertices.ToArray();
w.triangles = triangles;
w.RecalculateNormals();
mf.mesh = w;
}
}
follow the tutorial on $$anonymous$$STV.com as there is more but what you want to do is have a perant object like WaterGrid and inside thathave a game object called waterChunk
on the make a script called WaterChunk that will generate a 16 x 16 grid of verticies and make this into a prefab.
then a script you attach to the waterGrid will then create the chunks in the correct place
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
I need to get a Vector3 of the mouse position while i'm editing in the scene view. 2 Answers
Voxel Dictionary Lookup Issues 0 Answers
Adding more Voxels to the mix 0 Answers