Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 funki · Apr 04, 2016 at 05:58 PM · terrain2d gametopdownperlin noiseperlin

2d Top-Down Perlin noise map using Mathf.PerlinNoise

Okay I don't really like asking for help, but here I go: I've been trying to make a 2d top-down terrain generator for my game ( something like dwarf fortress, just... simpler), and I managed to make one (Hooray!), but the terrain my script generates isn't really what I was trying to do. alt text I hope you get my idea, I want a more realistic, bumpy terrain. Here is my code:

 public class Generator : MonoBehaviour {
 
     
     public GameObject dirtPrefab;
     private GameObject C;
     private float maxX = 320;
     private float maxY = 320;
     private int seed;
     void Start()
     {
         Regenerate();
        
     }
 
     private void Regenerate(){
         float width = dirtPrefab.transform.lossyScale.x / 5;
         float height = dirtPrefab.transform.lossyScale.y / 5;
         for (float  i = 0; i < maxX; i++)
         {
             for (float k = 0; k < maxY; k++)
             {
                 var perlin = Mathf.PerlinNoise(i / 10, k / 10);
                 if (perlin >.5f)
                 {
                     C = (GameObject)Instantiate(dirtPrefab, new Vector3(i * width, k * height, 2), Quaternion.identity);
                     SpriteRenderer Sr1 = C.GetComponent<SpriteRenderer>();
                     Sr1.color = Color.green;
                 }
             }
         }
     }
 }

Any ideas on how I can get a better terrain generator?

,

terrain.png (150.2 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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by nisovin · Apr 04, 2016 at 11:34 PM

First, you're using 0.5 as a cutoff for "land" vs "not land". But what you really want to do is use that as a height value. You can see an immediate difference by changing your color:

 Sr1.color = new Color(0, perlin, 0);

This will make your land color change.

Second, you can try messing with your divisor when generating the Perlin noise. Right now you're using 10, but try using different numbers to see what the results are.

Third, you can try to offset the returned perlin value based on how far from the center of the map you are. Areas near the center would have a higher value, and areas farther away would have a lower value. This would kind of force the map to generate a mountain in the center with ocean around the edges.

Comment
Add comment · Show 2 · 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 funki · Apr 05, 2016 at 12:44 AM 0
Share

Alright, I tried everything you suggested, except the mountain thing (It isn't really what I'm trying to achieve) Here is what i modified:

var perlin = $$anonymous$$athf.PerlinNoise(i / 50, k / 55); Sr1.color = new Color(0, perlin, 0);

Changing the divisor to generate the noise only makes the islands bigger, but their shape stays the same. Isn't there a way to make natural looking islands using $$anonymous$$athf.PerlinNoise? $$anonymous$$aybe some way to affect the frecuency of the noise used to créate the perlin noise?

avatar image nisovin funki · Apr 06, 2016 at 06:15 PM 0
Share

Perlin noise is just noise, there are no options for it. It generates numbers that smoothly transition between 0 and 1, and that's it. You can use it as part of your process for generating an island, but you can't just use it directly. You should really try scaling by distance though, it'd probably help get what you're trying to achieve. But if you want something that really looks nice, it's gonna have to be more complicated.

avatar image
0

Answer by Benster1599 · Aug 06, 2017 at 01:03 AM

I know this post is quite old, but does anyone know how I could make this into an infinite terrain? Thanks

Edit: Sorry. This should be in the comments section.

Comment
Add comment · Show 3 · 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 RedHeart95 · Sep 16, 2017 at 12:45 PM 1
Share

Old post I know but for anyone that stumbles across this Sebastian Lague on YouTube dose some A class tutorials on this subject they are truly the best i have found. Link to his playlist below for anyone that is interested.

https://www.youtube.com/watch?v=wbp$$anonymous$$i$$anonymous$$iS$$anonymous$$m8&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3

avatar image Nobozarb · Jan 02, 2018 at 01:15 AM 0
Share

This is also a little late to be answering, but the Perlin noise map is either infinite or close enough to infinite for practical purposes. You can use chunks, and whenever a player approaches the edge of a chunk grab another bit of the map and use it to generate terrain.

avatar image FoolishTroll Nobozarb · Sep 16, 2020 at 08:02 PM 0
Share

Old post I know but for anyone that stumbles across this Sebastian Lague on YouTube dose some A class tutorials on this subject they are truly the best i have found. Link to his playlist below for anyone that is interested.

avatar image
0

Answer by JohnnyFactor · Sep 14, 2020 at 03:15 PM

Mix the perlin noise with a radial gradient to get an island in the center. I found an excellent blog post with various examples:

https://edwardtoy.wordpress.com/2014/01/16/final-year-project-lets-make-some-noise/

Comment
Add comment · 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

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do i procedurally generated perlin noise infinitely c# 0 Answers

Add perlin noise to blocky terrain 0 Answers

Layer Sprites Based on Y axis 1 Answer

Character looking at opposite direction of mouse 1 Answer

how to make a pushable object in a 2D top-down game? (no gravity) 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