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
1
Question by Sleeper75 · Oct 01, 2013 at 04:33 AM · javascriptrandomminecraftperlin noiseinfinite terrain

How to generate infinite cube world / minecraft terrain with perlin noise?

NOTE: This is NOT Me asking you to give me the code as that would be completely unfair to you and to me, In the sense that i would not be learning anything at all. Or me trying to make a Minecraft / Cube World clone. I am 15 years old and have been using Unity3D for a very long time now, I have become very advanced in Unity's interface and have taken up Javascript to forward my knowledge in Game development. For a small project i would like to learn first off, How to use perlin noise to generate Minecraft like terrain that is infinite in all directions except down, Down it should be 10 blocks (It's more of a exploration game then a mining game like minecraft and others) Once that has been achieved (And i know it wont be easy) i would like to also learn how to add different bioms Example: basic and most common is the wasteland, small pools of acid, tiny town like structures that will be made of prefabs i designed or just cube placeholders. I have many more things to ask but this is the most important and difficult wall i have to overcome. Thank you for your time in anwsering my question, Any feedback would be appreciated :) (Sorry if i misspelled some things my first language is not english)

Comment
Add comment · Show 2
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 flaviusxvii · Oct 02, 2013 at 02:58 AM 0
Share

Use Google. This has been asked and answered quite a lot.

avatar image Sleeper75 · Oct 11, 2013 at 06:34 AM 0
Share

The reason i asked on here is because i couldint get an anwser off of google from weeks of trying :P

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by brandonsay95 · Oct 10, 2013 at 07:54 PM

to generate a 16X16 chunk i use

for (float px = 0; px < width; px ++) { for (float py = 0; py< width; py ++) {

             System.Random rnd = new System.Random();
                 var Perlin1 = Mathf.PerlinNoise((px+ transform.position.x) /a, b);
                 var Perlin2 = Mathf.PerlinNoise((py+ transform.position.z) /a, b);
             
                 createCube(new Vector3(px + transform.position.x
                                    , Mathf.FloorToInt(Perlin1*40*Perlin2),
                                    py + transform.position.z));
 
     
     
     
     
         }
     }



I have updated the chunk generator now you can set a render distance allowing you to render new chunks prier to you heading to the edge of a chunk

using UnityEngine; using System.Collections;

public class ChunkMap : MonoBehaviour { public Transform Chunk; public Transform player; int chunksize = 16; int render_distance = 6;

 // Use this for initialization
 void Start () {
     GenerateChunks();
     
     
 
 }
 
 void GenerateChunks()
 {
     Vector3[] chunks = new Vector3[render_distance*render_distance];
     bool[] chunksbool = new bool[render_distance*render_distance];
     
     int i = 0;
     
     for(int x=(render_distance/2)*-1;x<render_distance/2;x++)
     {
     for(int z=(render_distance/2)*-1;z<render_distance/2;z++)
     {
             int px = Mathf.RoundToInt(player.transform.position.x /16) * 16;
             int pz = Mathf.RoundToInt(player.transform.position.z /16) * 16;
             px = px+(x*16);
             pz = pz+(z*16);
         chunks[i] = new Vector3(px,0,pz);
             chunksbool[i] = true;
                 i=i+1;
     }
     }
     
     for(i=0;i<render_distance*render_distance;i++)
     {
         foreach (Transform child in transform)
         {
                if(child.transform.position == chunks[i])
             {
                 chunksbool[i]=false;
                 
                 
             }
         }
         
     }
     for(i=0;i<render_distance*render_distance;i++)
     {
         if(chunksbool[i])
         {
             CreateChunk(chunks[i]);
         }
     }
     
     
     
 }
 
 
 void CreateChunk(Vector3 pos)
 {
     Transform chunk = Instantiate(Chunk,pos,Quaternion.identity) as Transform;
     chunk.transform.parent = transform;
     
 }
 void DestroyChunks()
 {
     int px = Mathf.RoundToInt(player.position.x/16) * 16;
     int pz = Mathf.RoundToInt(player.position.z/16) * 16;
     int renderer = Mathf.RoundToInt(render_distance + (render_distance/2));
     
     
         foreach (Transform child in transform)
         {
         Vector2 ch = new Vector2(child.transform.position.x,child.transform.position.z);
         Vector2 pl = new Vector2(player.transform.position.x,player.transform.position.z);
         
                
         float dist = Vector2.Distance(ch,pl);
         
             if(dist>renderer*20)
         {
         
             
             Destroy(child.gameObject);
             
         }
                 
         }
     
     
 }
 
 // Update is called once per frame
 void Update () {
 
         GenerateChunks();
         DestroyChunks();
     
 
                     
                     
                     
     
 }
 
 

     

}

Comment
Add comment · Show 1 · 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 Sleeper75 · Oct 11, 2013 at 06:35 AM 0
Share

Thanks for the help brandon! If i need any other help i will be sure to pm you! :)

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

16 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

Related Questions

Random Terrain Generation (Trees, Details, Textures) by passing a Seed? 0 Answers

Random position without overlap. HELP! 1 Answer

Help with spawning an object in a random location 1 Answer

How to create random movement in 2D 2 Answers

How does Mathf.PerlinNoise Work? 4 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