Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MakakWasTaken · Sep 20, 2015 at 12:25 PM · c#gridwatervoxel

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.

Comment
Add comment · Show 12
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Sep 20, 2015 at 03:53 PM 0
Share

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.

avatar image MakakWasTaken · Sep 20, 2015 at 03:57 PM 0
Share

I would like to make river system for procedural terrains. I just assumed that making a grid based system would be easier.

  • $$anonymous$$akak

avatar image Cherno MakakWasTaken · Sep 20, 2015 at 04:53 PM 0
Share

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).

avatar image MakakWasTaken · Sep 20, 2015 at 10:28 PM 0
Share

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.

avatar image Cherno MakakWasTaken · Sep 21, 2015 at 10:41 AM 0
Share

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?

avatar image Runalotski · Sep 21, 2015 at 02:26 PM 0
Share

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

avatar image MakakWasTaken · Sep 21, 2015 at 05:03 PM 0
Share

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.

avatar image Cherno MakakWasTaken · Sep 21, 2015 at 06:10 PM 0
Share

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.

avatar image Runalotski MakakWasTaken · Sep 22, 2015 at 11:37 AM 0
Share

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

avatar image MakakWasTaken MakakWasTaken · Sep 22, 2015 at 12:09 PM 0
Share

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;
                 }
             }
avatar image Runalotski MakakWasTaken · Sep 22, 2015 at 12:21 PM 0
Share

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

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges