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 /
  • Help Room /
avatar image
0
Question by Genesis_Dev · Sep 16, 2020 at 12:01 PM · 2d gameperlin noise

2D world generation with perlin noise is producing regular terrain

Hello, I have a Perlin noise script on my 2d game that generates "random terrain" but so far it only generates perfect waves for the terrain.

If you only generate one it looks kind of good but when you start generating more the pattern starts being much more noticeable. alt text

From what I've gathered, the script seems to choose a fixed vertical position and then draw a wave to it multiple times, but I have no idea what-s causing that.

Here's the script: using UnityEngine; using UnityEngine.Tilemaps;

 public class proceduralgeneration : MonoBehaviour
 {
     [SerializeField] int width;
     [SerializeField] int minStoneheight, maxStoneHeight;
     [Range(0, 100)]
     [SerializeField] float heightValue, smoothness;
     [SerializeField] Tilemap grassTilemap, dirtTilemap, stoneTilemap;
     [SerializeField] Tile grass, dirt, stone;
     float seed;
 
     void Start()
     {
         seed = Random.Range(-1000000, 1000000);
         Generation();
     }
 
     private void Update() 
     {
         if(Input.GetKeyDown(KeyCode.O))
         {
             seed = Random.Range(-1000000, 1000000);
             Debug.Log(seed);
             Generation();
         } if(Input.GetKeyDown(KeyCode.P)) {
                grassTilemap.ClearAllTiles();
                dirtTilemap.ClearAllTiles();
                stoneTilemap.ClearAllTiles();
         }
     }
 
     void Generation()
     {
         for (int x = 0; x < width; x++)
         {
             int height = Mathf.RoundToInt(heightValue * Mathf.PerlinNoise(x / smoothness, seed));
 
             int minStoneSpawnDistance = height - minStoneheight;
             int maxStoneSpawnDistance = height - maxStoneHeight;
             int totalStoneSpawnDistance = Random.Range(minStoneSpawnDistance, maxStoneSpawnDistance);
 
             for (int y = 0; y < height; y++)
             {
                 if (y < totalStoneSpawnDistance)
                 {
                     stoneTilemap.SetTile(new Vector3Int(x, y, 0), stone);
                 }
                 else
                 {
                     dirtTilemap.SetTile(new Vector3Int(x, y, 0), dirt);
                 }
                
             }
             if(totalStoneSpawnDistance == height)
             {
                 stoneTilemap.SetTile(new Vector3Int(x, height, 0), stone);
             }
             else
             {
                 grassTilemap.SetTile(new Vector3Int(x, height, 0), grass);
             }   
         }
     }
 }

I also tried another kind of procedural generation, bu copying game objects and selecting a random value on where to put a tile (If next to, one block up or one block down), which never produced regular terrain but the curves and flat surfaces were choppy as there was random 1 block wide gaps and it wasn't optimized at all.

It would mean a lot if any of you could help me out, and as I'm starting with this as there could be something that might be off, thanks in advance :)

screenshot-2020-09-11-174018.png (3.3 kB)
screenshot-2020-09-11-174036.png (4.0 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

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.

Follow this Question

Answers Answers and Comments

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

Player follows mouse, but I need only Y 1 Answer

2D Rotation with Quaternion gets stuck... 1 Answer

How to lock the camera on Y axis? 0 Answers

Arkanoid-like bounce troubles 1 Answer

How to avoid Bullets to Change speed while flying,How to avoid Bullets speed changing while the Bullet is flying 0 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