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 /
  • Help Room /
avatar image
0
Question by DutchGames · Jul 31, 2016 at 03:04 PM · generationtileperlin noise

Tile based river generation

I have made a map generation in my tile based game. It almost exactly does what I want, except for 1 thing. The rivers look like this:

alt text

The problem with this is, it's not realistic. It are just some spots random over the world. I want to make a realistic river generation. Which would include different sizes (between 5 and 20 block wide), branches, lakes and different depths. What is the best way to do that?

Here an example from Simcity 4 of what I mean with realistic rivers: alt text

This is my current code:

 waterOffsetX = Random.Range (10f, 300000f);
 waterOffsetX = Mathf.Round (waterOffsetX) + 0.5f;
 waterOffsetY = Random.Range (10f, 300000f);
 waterOffsetY = Mathf.Round (waterOffsetY) + 0.5f;
 
 for (float x = -gridX; x < gridX; x += 1)
 {
     for (float y = -gridY; y < gridY; y += 1) 
     {
         Vector3 spawnPos = new Vector3 (x, y, 0);
         float perlinWater = Mathf.PerlinNoise (x * seedWaterX + waterOffsetX , y * seedWaterY + waterOffsetY);
 
         if (perlinWater > perlinThresholdWater) {
         GameObject waterTile = Instantiate (water, spawnPos, Quaternion.identity) as GameObject;
     }
     }
 }
 
 Values:
 seedWater (X & Y) = 0.1
 Grid (X & Y) = 50
 perlinThresholdWater = 0.6


naamloos.png (106.8 kB)
map.jpg (17.1 kB)
Comment
Add comment · Show 6
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 Salmjak · Jul 31, 2016 at 03:13 PM 0
Share

@DutchGames I would personally make a "fake" heightmap and then start at the highest point and add the next lowest point/neighbour to a list, if there are several that are approximately the same I would start a new iteration from each (branching). Water flows down using (usually) the path of "least resistance" and reinforce the path (e.g. erosion of a mountain).

There might also be some kind of fractal-noise that produces good rivers. Look up LibNoise for Unity and Libnoise website.

avatar image Salmjak · Jul 31, 2016 at 04:02 PM 0
Share

@DutchGames Here is a mountain-range I recently made using LibNoise. To produce this mountain I use a ridged multifractal noise with low frequency as the base, then I add a higher frequency perlin noise to create the peaks within the bounds created by the base. On top of this I add a a higher frequency reversed (multiplied by -1) ridged multifractal noise to create recesses in the mountain.

Although this is in 3D it should give you some hints on were to start with your heightmap. Then use some kind of hill-climbing algorithm to get your path for the water in a 2D space.

alt text

2016-07-31-17-45-31-unity-personal-64bit-mysteryun.png (286.6 kB)
avatar image DutchGames · Jul 31, 2016 at 06:16 PM 0
Share

Wouldn't that cause some severe lag? I want my game to generate areas while playing.

avatar image Salmjak DutchGames · Jul 31, 2016 at 07:15 PM 0
Share

@DutchGames Then its a whole other problem :P Although, you could try with a reversed (multiplied by -1) ridged multifractal from Libnoise and create water were the output is greater than 0. The recursive hill-climbing might not take that long though, and you could always limit it. I also noticed that a single ridged multifractal noise is enough to create good looking mountains. Remember that Deep Blue could evaluate 2 million positions per second and an A* pathfinding algorithm of $$anonymous$$e could look through 10,000s of nodes in a matter of milliseconds. Given that you will just create a primary path with the hill-climbing it shouldnt be a problem.

Otherwise it's probably better to just code your own algorithm for creating rivers and lakes.

avatar image Salmjak Salmjak · Jul 31, 2016 at 07:22 PM 0
Share

@DutchGames Also, if you don't do it already: Look up how to use chunks and only load/create visible chunks and pool your gameobjects.

avatar image Salmjak DutchGames · Jul 31, 2016 at 07:31 PM 0
Share

@DutchGames To sum it up, this is how I would do it: Create your area using nested for-loops and make a height map for the area using Ridged $$anonymous$$ultifractal, here we should keep track of the highest point and it's coordinates.

When that's done, take the highest point and start with the hill-climbing. The hill-climbing is basically: Add the current coordinate to a list of nodes, get all the neighbours of this node. Pick the neighbour with the smallest height-value according to our height map. Do this recursively until either all neighbours have higher or the same height as the current node or until a preset amount (say 50 nodes).

But that's just how I would do it :) Depending on the size you're trying to create and how long you want your rivers this can take some time.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Generating Y values for dynamically generated terrain LOD 0 Answers

Question about procedural forest/grass generation 1 Answer

Generated tiles are displayed wrong in the camera view but they are appearing right in the scene window 0 Answers

Problems with the way my sprites look 2 Answers

Why won't my random tile generator not working?? 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