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 Kshizzle · Sep 17, 2017 at 07:05 PM · 2dprocedural generationperlin noisemap makingmap-generation

Adding rivers to procedural generated 2D map

I'm using a noise function to procedurally generate a tile map, I was wondering if there is any way to extend what I'm already using to add the ability to create rivers to the map generation.

Currently I'm getting this: map

And I'd like to find a method of doing this: map with river Where large bodies of water are connected to one another as if they were a single continuous flow.

I have a Noise class that makes the values for the map.

 public class Noise {
 
     int seed;
     float frequency;
     float amplitude;
 
     float lacunarity;
     float persistance;
 
     int octaves;
 
     public Noise (int seed, float frequency, float amplitude, float lacunarity, float persistance, int octaves)
     {
         this.seed = seed;
         this.frequency = frequency;
         this.amplitude = amplitude;
         this.lacunarity = lacunarity;
         this.persistance = persistance;
         this.octaves = octaves;
     }
 
     public float[,] GetNoiseValues(int width, int height)
     {
         float[,] noiseValues = new float[width, height];
 
         float max = 0f;
         float min = float.MaxValue;
 
         for (int i = 0; i < width; i++) {
             for (int j = 0; j < height; j++) {
 
                 noiseValues [i, j] = 0f;
 
                 float tempA = amplitude;
                 float tempF = frequency;
 
                 for (int k = 0; k < octaves; k++) {
 
                     noiseValues [i, j] += Mathf.PerlinNoise ((i + seed) / (float)width * frequency, (j + seed) / (float)height * frequency) * amplitude;
                     frequency *= lacunarity;
                     amplitude *= persistance;
                 }
 
                 amplitude = tempA;
                 frequency = tempF;
 
                 if (noiseValues [i, j] > max)
                     max = noiseValues [i, j];
 
                 if (noiseValues [i, j] < min)
                     min = noiseValues [i, j];
             }
         }
         for (int i = 0; i < width; i++) {
             for (int j = 0; j < height; j++) {
 
                 noiseValues [i, j] = Mathf.InverseLerp (max, min, noiseValues [i, j]);
 
             }
         }
         return noiseValues;
     }
 }

And in my main class the map is created with the following function:

 float[,] noiseValues = noise.GetNoiseValues (width, height);
 
         for (int x = 0; x < Width; x++) {
             for (int y = 0; y < Height; y++) {
                 tiles[x,y] = new Tile(x, y);
                 if (noiseValues[x,y]  < 0.2f) {
                     tiles [x, y].Type = TileType.Shallow;
                 } else if (noiseValues[x,y]  < 0.4f) {
                     tiles [x, y].Type = TileType.Grass;
                 } else if (noiseValues[x,y]  < 0.55f) {
                     tiles [x, y].Type = TileType.Scrub;
                 } else if (noiseValues[x,y]  < 0.6f) {
                     tiles [x, y].Type = TileType.Marsh;
                 } else if (noiseValues[x,y] < 1f) {
                     tiles [x, y].Type = TileType.Bare;
                 }
             }
         }

I'm very new to Unity and C#, I've done some reading around generating biomes but the math is somewhat above my head. Is it possible to extend what I have to accomplish river generating? Or could I use something like PathA* to join two points on a map to get the result I want? Thanks!

Comment
Add comment · Show 1
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 18, 2017 at 09:23 AM 0
Share

It's mostly a math problem I figure. I also figure that you will be able to find several example mathematical equations that simulate a river with bends.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ThibaultCoutaz · Dec 22, 2017 at 10:23 AM

I think A* would do perfectly the work for you

alt text

to train PathFinding with A* i made a 2 grids with some wall (in your case the wall can be the black pixel )

Picture explication :

Black pixel = wall; White pixel = free Space where the way can pass. pink pixel = free Space visit by the A* yellow pixel= Wall visit by the A* blue/cyan pixel = Way to go from A to B Red pixel = Point B : End Green Pixel = Point A: Start


pathfinding.jpg (95.0 kB)
Comment
Add comment · Share
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

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

133 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 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 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 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 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

2d tilemap with biomes and perlin noise 1 Answer

Advice on 2D Surface Terrain Generation Using Noise 1 Answer

Better perlin noise map generation. 0 Answers

How do I make an interactive map on Unity? 0 Answers

2D Animation does not start 1 Answer


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