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 beau101023 · May 21, 2015 at 06:17 AM · c#terraingenerationgeneratorflat

Terrain Generator Producing Completely Flat Results.

My terrain generator is failing to produce any variation in height whatsoever. The logic seems to work out fine on paper. The system is supposed to work by alternating between a system of deriving rows of cube heights progressively, taking the height of the previous cube and adjusting the next up, down, or not at all, and a system of deriving the next row's height map from the previous row.

 using UnityEngine;
 using System.Collections;
 
 
 public class Terrain_Generator : MonoBehaviour 
 {
     public GameObject Target_Obj;
     int width = 5;
     int iteration;
     int length = 5;
     public int height;
     int prevPos;
     int height0;
     int height1;
     int height2;
     int height3;
     int height4;
     int height5;
     int horizPos;
     void Start () 
     {
         //j controls the x coord.
         for (int j=0; j<width; j = j + 1) 
         {
             prevPos = 0;
             //i controls the z coord.
             for (int i=0; i<length; i = i + 1) 
             {
                 /*Sets the horizPos to generate cubes 1 unit below or above the previous cube's 
                 position, as well as in the same position height-wise.*/
                 if(j == 0 && j == 2 && j == 4)
                 {
                     horizPos = Random.Range (prevPos + height, prevPos - height * 2);
                 }
                 //Generates the cube's height based on the corresponding cube in the previous row.
                 if(j == 1 && j == 3 && j == 5)
                 {
                     if(i == 0) 
                     {
                         horizPos = Random.Range (height0 + height, height0 - height * 2);
 
                     }
                     if(i == 1) 
                     {
                         horizPos = Random.Range (height1 + height, height1 - height * 2);
                     }
                     if(i == 2) 
                     {
                         horizPos = Random.Range (height2 + height, height2 - height * 2);
                     }
                     if(i == 3) 
                     {
                         horizPos = Random.Range (height3 + height, height3 - height * 2);
                     }
                     if(i == 4) 
                     {
                         horizPos = Random.Range (height4 + height, height4 - height * 2);
                     }
                     if(i == 5) 
                     {
                         horizPos = Random.Range (height5 + height, height5 - height * 2);
                     }
                 }
                 Object.Instantiate (Target_Obj, new Vector3 (j, horizPos, i), Quaternion.identity);
                 prevPos = horizPos;
                 //Stores y coord of previous j iteration's cubes in order.
                 if(i == 0)
                 {
                     height0 = horizPos;
                 }
                 if(i == 1)
                 {
                     height1 = horizPos;
                 }
                 if(i == 2)
                 {
                     height2 = horizPos;
                 }
                 if(i == 3)
                 {
                     height3 = horizPos;
                 }
                 if(i == 4)
                 {
                     height4 = horizPos;
                 }
                 if(i == 5)
                 {
                     height5 = horizPos;
                 }
             }
         }
     }
     void Update () 
     {
 
     }
 }
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
1
Best Answer

Answer by tanoshimi · May 21, 2015 at 06:54 AM

The parameters for Random Random.Range are (min, max).

It looks like you're supplying (max, min) every time.

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 beau101023 · May 21, 2015 at 07:49 PM 0
Share

D'oh. Thanks for pointing this out. I feel silly now. :P

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

2 People are following this question.

avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Code Loops Indefinitely 1 Answer

Procedural 2D Tilemap Terrain - Mesh or Unity Tilemaps? 0 Answers

[C#] 2D infinite Terrain Generation with prefabs?! -> lag 0 Answers

Is there a way to load premade terrain chunks randomly? 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