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 /
This question was closed Feb 06, 2019 at 08:04 PM by Peakz for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Peakz · Jan 22, 2019 at 08:43 PM · 2dprocedural generationperlin noisenoiseterrain generation

Advice on 2D Surface Terrain Generation Using Noise

Not a super in depth question, just looking for some advice on how to approach this section of terrain generation.


Current Script


Currently, I have a script which generates the 'underworld' terrain using Cellular Automata. Here is a screenshot of a sample generation:


alt text


I have a map array which consists of either a 0 or 1 for each coordinate within the map - here is a sample:


 // Filling tiles and creating cave
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 if (x == 0 || x == width - 1 || y == 0) // Add  || y == height - 1 to remove surface openings
                 {
                     map[x, y] = 1; // Tiles around the edge are always filled
                 }
                 else
                 {
                     map[x, y] = (pseudoRandom.Next(0, 100) < caveFillPercent) ? 1 : 0; // If less than fillPercent, fill. Otherwise leave blank (cave)
                 }
             }
         }


If the map array coordinate is then equal to 1, the tile to spawn is then calculated on a separate section of the script using Perlin Noise - here is a sample:


 if (map[xx, yy] >= 1) // If map index is a filled tile (not empty)
                 {
                     GameObject selectedTile = null;
 
                     selectedTile = stoneTile;
                     map[xx, yy] = 1;
 
                     // Adjust noise values according to rarity of each ore
                     float DiamondOreNoise = Mathf.PerlinNoise((x / 4) + seed, (y / 4) + seed);
                     float GoldOreNoise = Mathf.PerlinNoise((x / 5) + seed, (y / 5) + seed);
                     float IronOreNoise = Mathf.PerlinNoise((x / 8) + seed, (y / 8) + seed);
                     float CoalOreNoise = Mathf.PerlinNoise((x / 10) + seed, (y / 10) + seed);
     
                     if (cavernBiome)
                     {
                         if (DiamondOreNoise > 0.92)
                         {
                             selectedTile = diamondTile;
                         }
                         if (GoldOreNoise > 0.90)
                         {
                             selectedTile = goldTile;
                         }
                         if (IronOreNoise > 0.86)
                         {
                             selectedTile = ironTile;
                         }
                         if (CoalOreNoise > 0.80)
                         {
                             selectedTile = coalTile;
                         }
                     }
 
                     if (hellBiome)
                     {
                         selectedTile = obsidianTile;
                     }
 
                     GameObject newTile;
                     newTile = Instantiate(selectedTile, new Vector2(x, (y - height) + 1), Quaternion.identity);
                     newTile.transform.SetParent(gameObject.transform, false);
                 }


My Question


My question is: when generating the 'surface' terrain with Perlin Noise, what would be the best - or most efficient - way to approach this?


Would the best approach utilize the 'map[x, y]' array somehow in conjunction with a new 'surface Perlin Noise'? If so, how would I approach this?

Or would the best approach even be starting in another script, completely separate to this?


Any advice would be greatly appreciated!

map-sample.png (79.5 kB)
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 Peakz · Jan 23, 2019 at 11:41 PM 0
Share

Looking at the rest of my code I am pretty sure I would not be able to use the map array for the surface generation. For example I have specific code which checks for 'small gaps' (small caves which should be filled), this would interfere with any surface terrain generated using the map array. Not to mention the map[x, y] = (pseudoRandom.Next(0, 100) < caveFillPercent) ? 1 : 0;.

1 Reply

  • Sort: 
avatar image
0

Answer by pmerilainen · Jan 24, 2019 at 09:52 AM

Your question is very vague. It is not clear if the game is Terraria-styled side scroller or top-down dungeon crawler/miner game.

Generating surface terrain for Terraria style is totally different to generating terrain to topdown game.

For side view i think a noise wave (or sum of different frequency noise waves) to determine terrain height is good way, then sporadically create trees etc. on the surface. For topdown view you could use the cellular automata approach to generate patches of forests/grass/sand etc..

Comment
Add comment · Show 3 · 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
avatar image Peakz · Jan 24, 2019 at 11:07 AM 0
Share

Thanks for your reply. I am ai$$anonymous$$g for a Terraria-styled side-scroller. So you are suggesting I use the sum of several Perlin Noise waves to set the height for each Y coordinate of my map (I am presu$$anonymous$$g I would customize the noise to give me a smoother desired output), but how would I approach sporadically creating trees upon this terrain?

avatar image pmerilainen Peakz · Jan 25, 2019 at 11:09 AM 0
Share

The simplest way is just drop them randomly and ensure they are not too close to each other. You can also add "gap rules" that prevent generation of stuff to a certain area as well.

avatar image Peakz pmerilainen · Jan 28, 2019 at 10:35 PM 0
Share

Okay I have the random generation of trees working. By adding 'gap rules', would this just be simply checking for a nearby tree at the given x any y coords, before spawning?

Follow this Question

Answers Answers and Comments

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

Generating Chunks of Ore Using Perlin Noise 3 Answers

2d tilemap with biomes and perlin noise 1 Answer

[C#] Wondering what is amiss with my 1D Perlin Noise Terrain Generator? 2 Answers

2D topdown generating stairs (access) to generated hill 0 Answers

How can i make this noise generated terrain more interesting? 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