Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Daniel-Everland · Sep 14, 2014 at 02:52 PM · c#procedural generation

Generating terrain radially

So I've been spending a few hours now looking for an algorithm to help me radially generate terrain. All I've been able to find is articles of people asking how to generate terrain like in Terraria, however, that's not what I'm after

Specifically I'm going to use this to random generate asteroids of various sizes, with various minerals and such. From looking at the above mentioned articles, I've been able create Terraria like terrain using the following code. Which is a slightly modified version of the popular tutorial found here

 GameObject Stone = (GameObject)Resources.Load("Stone");
         GameObject Grass = (GameObject)Resources.Load("Grass");
         byte[,] blocks = new byte[x, y];
 
         for (int px = 0; px < blocks.GetLength(0); px++)
         {
             int stone = NoiseGenerator.Noise(px, 0, 20, 20, 1);
             stone += NoiseGenerator.Noise(px, 0, 50, 30, 1);
             stone += NoiseGenerator.Noise(px, 0, 10, 10, 1);
             stone += 25;
 
             int grass = NoiseGenerator.Noise(px, 0, 100, 35, 1);
             grass += NoiseGenerator.Noise(px, 0, 50, 30, 1);
             grass += 25;
 
             for (int py = 0; py < blocks.GetLength(1); py++)
             {
 
                 if (NoiseGenerator.Noise(px, py, 12, 16, 1) > 10)
                 {
                     Instantiate(Grass, new Vector3(px, py), Quaternion.identity);
                 }
                 else if (py < stone && py > -stone /*&& NoiseGenerator.Noise(px, py*2, 16, 14, 1) < 10*/)
                 {
                     Instantiate(Stone, new Vector3(px, py), Quaternion.identity);
                 }
                 else if (py < grass && py > -grass/*&& NoiseGenerator.Noise(px, py * 2, 16, 14, 1) < 10*/)
                 {
                     Instantiate(Grass, new Vector3(px, py), Quaternion.identity);
                 }                
             }
         }


What I can't for the life of me wrap my head around, is how would one modify this to create an asteroid-like shape.

Thanks in advance :)

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

1 Reply

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

Answer by VesuvianPrime · Sep 14, 2014 at 03:47 PM

I suppose one way of generating random asteroid shapes would be to create a map and repeatedly draw random circles to it:

  1. Create a 2d integer array the size of your asteroid. Zeroes will be empty space, Ones will be filled with tiles.

  2. Get a random number of circles.

  3. Calculate the maximum radius for a circle to fit in the array.

  4. For each circle: 5. Calculate a random radius up to the max radius 5. Calculate a random position such that a circle of given radius will fit in the array. 6. "Draw" the circle to the 2d array (for each pixel of the circle, set a 1 to the array), looks like this should work: http://stackoverflow.com/questions/1201200/fast-algorithm-for-drawing-filled-circles

  5. You should now have a 2d array of 1s and 0s marking the shape of your asteroid. You can use this as a lookup table in your tile generation to see if a tile should be created or not.

Comment
Add comment · Show 4 · 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 Daniel-Everland · Sep 14, 2014 at 09:48 PM 1
Share

Thanks, that worked out great! $$anonymous$$uch less painful than I thought it wouldn've been :)

If anyone is interested in the code I got from this, here it is;

 GameObject Stone = (GameObject)Resources.Load("Stone");
         int[,] intArray = new int[ArrayX, ArrayY];
                 
         for (int y = -Radius; y <= Radius; y++)
         {
             for (int x = -Radius; x <= Radius; x++)
             {
                 if (x * x + y * y <= Radius * Radius)
                 {
                     Instantiate(Stone, new Vector3(x, y), Quaternion.identity);
                 }
             }
         }
avatar image DarkSinBad Daniel-Everland · Mar 22, 2018 at 08:57 AM 0
Share

Thank you $$anonymous$$ :) simple and great ;)

avatar image VesuvianPrime · Sep 14, 2014 at 09:55 PM 0
Share

Aha! You were just making one circle! Well, I'm glad you figured it out. Nice work!

avatar image Daniel-Everland · Sep 14, 2014 at 10:50 PM 0
Share

Thanks, if you don't $$anonymous$$d me asking, could you help me out a bit with the perlin noise? I'm practically reusing the exact same method as I used to, which is giving me symmetrical distortion.

If I were to ditch the old 2D perlin noise, how should I approach a new method, specifically for circles? After doing a bit of research I saw that someone used a 1D algorithm - is this preferred when dealing with circles, rather than terrain?

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

25 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Implementation of directional buildings? 1 Answer

How to render procedurally generated mesh to be rendered as 2 sided? 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