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
1
Question by Peakz · Jan 01, 2019 at 10:34 PM · 2dperlin noiseprocedural-generationnoiseterrain generation

Generating Chunks of Ore Using Perlin Noise

Hi all,

I have a script which generates ore around a cave system based on Perlin noise values:

// Spawn tiles for (float x = 0; x < width; x++) { for (float y = 0; y < height; y++) { int xx = Mathf.RoundToInt(x); //Int required for map[] check, float required for noise int yy = Mathf.RoundToInt(y);

              if (map[xx, yy] == 1) // If map index is a filled tile (not empty);
              {
                  GameObject selectedTile = null;
                  int seed = UnityEngine.Random.Range(0, 9999);
                  float oreNoise = Mathf.PerlinNoise((x / frequency) + seed, (y / frequency) + seed);
                  if (oreNoise > 0.95)
                  {
                      selectedTile = diamondTile;
                  }
                  else if (oreNoise > 0.90)
                  {
                      selectedTile = goldTile;
                  }
                  else if (oreNoise > 0.87)
                  {
                      selectedTile = ironTile;
                  }
                  else if (oreNoise > 0.80)
                  {
                      selectedTile = coalTile;
                  }
                  else
                  {
                      selectedTile = stoneTile;
                  }
                  GameObject newTile;
                  newTile = Instantiate(selectedTile, new Vector2(x, y), Quaternion.identity);
                  newTile.transform.SetParent(gameObject.transform, false);
              }
          }
      }

With the focus being on:

float oreNoise = Mathf.PerlinNoise((x / frequency) + seed, (y / frequency) + seed);

Currently this script will generate single-ore veins around the map:

alt text

My question is: how do I adjust this script so the ore spawns in chunks (as seen in Terraria for example)? I understand this would mean I would need bigger patches of higher value perlin noise, however after researching further into Perlin noise, I am still unsure how to generate noise which appears more so in 'patches'.

I have messed around with different frequencies, multiplied by different scales, added different octaves, of which none seem to add the 'chunkier' effect I am looking for.

Any suggestions/explanations would be greatly appreciated.

oregeneration.png (114.7 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by MixGrey · Jan 01, 2019 at 10:57 PM

You're choosing a new seed for the Perlin noise inside the loop, every time you get a value from it. What this means is that you're basically creating an entirely new Perlin noise "image" for every tile, instead of creating one Perlin noise image for the whole map and then having each tile sample from that one noise image.

You need to choose a seed outside of the loop, then use the same seed each time you call the Perlin noise function. Once you do that, adjusting the frequency should do what you expect it to do.

Once you fix that, you will encounter a second issue: the conditional branches you've set up for selecting the type of ore will tend to cause diamond to be surrounded by gold, and gold will tend to be surrounded by iron. This is because the Perlin noise function generates something like a heightmap, and you're using peaks for diamond and areas slightly below peaks for gold, etc.

The way most games do this is they use a different Perlin noise seed for each type of ore. The peaks of the diamond Perlin noise can spawn diamonds. The peaks of the gold Perlin noise can spawn gold, etc.

Hope this helps!

Comment
Add comment · Show 2 · 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 Razor1994 · Jan 01, 2019 at 11:29 PM 0
Share

Also just a little tip when working with noise, maybe consider checking out fastnoise (you can find it on github) its alot faster than the default PerlinNoise method.

avatar image Peakz · Jan 02, 2019 at 02:07 AM 0
Share

Thank you for this informative answer, very helpful!

avatar image
0

Answer by DownER149 · Jan 02, 2019 at 12:18 AM

newTile = Instantiate(selectedTile, new Vector2(x, y), Quaternion.identity); put a component on the script with something like on start raycast rect( or use the the collider already on the tile) for each object in the raycast array (assumeing there is already dirt nearby with colliders) give it say a 50% chance to turn the tile next to it into the same type of ore so the first tile will hit 8 so four of thoes will turn into ore, then maybe decrease the chance each time the tile branchs out so maybe the next tiles wich will be less than 4 have a 25% then again 5% this will cause each ore to kind of bloom from its center spawn point

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
avatar image
0

Answer by AliAnkara · Feb 23, 2019 at 01:28 PM

see you guys are WebGL experts. I couldn't run the Cookies. I don't know how it works :(

I need an example on this. Is it possible to send me sample code?

Unity 3D 2018.2.5f1.... WebGL

Thank you from now... Ali

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

200 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 avatar image

Related Questions

Advice on 2D Surface Terrain Generation Using Noise 1 Answer

How can i make this noise generated terrain more interesting? 1 Answer

2d tilemap with biomes and perlin noise 1 Answer

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

Procedural Tree Placement using perlin noise 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