• 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 Ian9921 · Jun 24, 2018 at 02:39 AM · javascriptterraingenerationminecraftblocks

World Generation with Interesting Terrain

Okay, so I'm in a bit of a tricky situation. I'm making a game which some might describe as a Minecraft ripoff, and Im having some trouble with world generation. As it stands, I can procedurally generate what amounts to a big, near-perfect cube of various blocks with no noticeable hills, mountains, or other terrain.

This is, obviously, a problem.

What I'm basically looking for is a way to have the generation of blocks slowly taper off at certain points, dependent on the height and whether or not the previous layer had any "air blocks" (empty game objects which serve as filler for empty spaces during generation), but I'm not married to that notion. Any help or better ideas would be appreciated. I'll post the code I've got, so you know how everything's working so far, but be warned, it is a mess.

 public var blocksToGen = 100;
 public var blocksGenned = 0;
 public var rowsGenned = 0;
 static var worldBuilt : boolean = false;
 var rowOffset : boolean = false;
 var xPos = 0;
 var yPos = 0;
 var zPos = 0;
 var lowerBlocks = new Array();
 var upperBlocks = new Array();
 var blockToGen : int = 0;
 var layersGenned = 0;
 public var maxHeight = 100;
 public var seaLevel : int;
 public var heightOffset : double;
 var replacementBlock : int = 1;
 
 function Start () {
 
     lowerBlocks[0] = blackstone;
     lowerBlocks[1] = stoneBlock;
     lowerBlocks[2] = dirtBlock;
     lowerBlocks[3] = airBlock;
     lowerBlocks[4] = airBlock;
     lowerBlocks[5] = airBlock;
     lowerBlocks[6] = stoneBlock;
     lowerBlocks[7] = stoneBlock;
     lowerBlocks[8] = stoneBlock;
     lowerBlocks[9] = stoneBlock;
     lowerBlocks[10] = stoneBlock;
     lowerBlocks[11] = stoneBlock;
     lowerBlocks[12] = stoneBlock;
     lowerBlocks[13] = stoneBlock;
 
     upperBlocks[0] = blackstone;
     upperBlocks[1] = airBlock;
     upperBlocks[2] = airBlock;
     upperBlocks[3] = airBlock;
     upperBlocks[4] = airBlock;
     upperBlocks[5] = dirtBlock;
     upperBlocks[6] = dirtBlock;
     upperBlocks[7] = dirtBlock;
     upperBlocks[8] = dirtBlock;
     upperBlocks[9] = dirtBlock;
     upperBlocks[10] = dirtBlock;
     upperBlocks[11] = dirtBlock;
     upperBlocks[12] = stoneBlock;
     upperBlocks[13] = stoneBlock;
 
 
     while (layersGenned <= maxHeight) {
         while (rowsGenned < blocksToGen * 2) {
             while (blocksGenned < blocksToGen){
                 if (yPos == 0){
                     blockToGen = 0;
                 } else {
                     blockToGen = Random.Range(1,14);
                 }
                 if (layersGenned <= seaLevel) {
                     Instantiate(lowerBlocks[blockToGen], Vector3 (xPos, yPos, zPos), Quaternion.Euler(Vector3(90, 0, 0)));
                 } else {
                     Instantiate(upperBlocks[blockToGen], Vector3 (xPos, yPos, zPos), Quaternion.Euler(Vector3(90, 0, 0)));
                 }
                 blocksGenned += 1;
                 xPos = xPos + 2.15;
             }
             blocksGenned = 0;
             zPos = zPos + 1.89;
             //zPos = zPos + 1.89;
             if (rowOffset == false){
                 xPos = 1.075;
                 rowOffset = true;
             } else {
                 xPos = 0;
                 rowOffset = false;
             }
             rowsGenned = rowsGenned + 1;
         }
         layersGenned = layersGenned + 1;
         yPos = yPos + heightOffset;
         rowsGenned = 0;
         blocksGenned = 0;
         xPos = 0;
         zPos = 0;
     }
 }

EDIT: So what I'm thinking right now is to add a second layer of randomness, basically generating a random number from 1-4 and adding an additional block if the number is 1, or something like that. Unless I get any better ideas, I'll be going with that.

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

151 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

Related Questions

This script really makes my game lag! 1 Answer

Minecraft (Cube) Terrain 1 Answer

Voxel based Terrain generation. Pointers please. 2 Answers

Minecraft world generation in JavaScript 0 Answers

Object Refrence Not Set To An Instance Of An Object? 2 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