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 thebigjeff101 · Oct 12, 2021 at 03:28 AM · perlin noisenoisefalloff

How To Add Fallof to perlin?

So recently I have been experimenting with Perlin noise and wanted to start making some islands using a tile-based system. And so I found a youtube tutorial that helped me make a Perlin tiled based environment because when it comes to programming I'm still very much an amateur. However, I never figured out how to make an island until recently and it turns out that I need to add a fall of map. The problem is I don't know how to do that with the code I have. And so id like to ask if someone could help me out with implementing some sort of fall off map in my code that can help create an island or islands.

 public class MapFunction : MonoBehaviour
 {
     Dictionary<int, GameObject> tileset;
     Dictionary<int, GameObject> tile_groups;
     public GameObject prefab_snow;
     public GameObject prefab_snowForest;
     public GameObject prefab_mountain;
     public GameObject prefab_closeocean;
     public GameObject prefab_ocean;
 
 
 
 
 
 
 
 
     int map_width = 320;
     int map_height = 180;
 
     List<List<int>> noise_grid = new List<List<int>>();
     List<List<GameObject>> tile_grid = new List<List<GameObject>>();
 
     // recommend 4 to 20
     float magnification = 50.0f;
 
     int x_offset = 1; // <- +>
     int y_offset = 1; // v- +^
 
 
     void Start()
     {
         CreateTileset();
         CreateTileGroups();
         GenerateMap();
     }
 
     void CreateTileset()
     {
         /** Collect and assign ID codes to the tile prefabs, for ease of access.
             Best ordered to match land elevation. **/
 
         tileset = new Dictionary<int, GameObject>();
         tileset.Add(4, prefab_mountain);
         tileset.Add(3, prefab_snowForest);
         tileset.Add(2, prefab_snow);
         tileset.Add(1, prefab_closeocean);
         tileset.Add(0, prefab_ocean);
 
     }
 
     void CreateTileGroups()
     {
         /** Create empty gameobjects for grouping tiles of the same type, ie
             forest tiles **/
 
         tile_groups = new Dictionary<int, GameObject>();
         foreach (KeyValuePair<int, GameObject> prefab_pair in tileset)
         {
             GameObject tile_group = new GameObject(prefab_pair.Value.name);
             tile_group.transform.parent = gameObject.transform;
             tile_group.transform.localPosition = new Vector3(0, 0, 0);
             tile_groups.Add(prefab_pair.Key, tile_group);
         }
     }
 
     void GenerateMap()
     {
         /** Generate a 2D grid using the Perlin noise fuction, storing it as
             both raw ID values and tile gameobjects **/
 
         for (int x = 0; x < map_width; x++)
         {
             noise_grid.Add(new List<int>());
             tile_grid.Add(new List<GameObject>());
 
             for (int y = 0; y < map_height; y++)
             {
                 int tile_id = GetIdUsingPerlin(x, y);
                 noise_grid[x].Add(tile_id);
                 CreateTile(tile_id, x, y);
             }
         }
     }
 
     int GetIdUsingPerlin(int x, int y)
     {
         
         /** Using a grid coordinate input, generate a Perlin noise value to be
             converted into a tile ID code. Rescale the normalised Perlin value
             to the number of tiles available. **/
 
         float raw_perlin = Mathf.PerlinNoise(
             (x - x_offset) / magnification,
             (y - y_offset) / magnification
         );
         float clamp_perlin = Mathf.Clamp01(raw_perlin); // Thanks: youtu.be/qNZ-0-7WuS8&lc=UgyoLWkYZxyp1nNc4f94AaABAg
         float scaled_perlin = clamp_perlin * tileset.Count;
 
 
 
 
 
         // Replaced 4 with tileset.Count to make adding tiles easier
         if (scaled_perlin == tileset.Count)
         {
             scaled_perlin = (tileset.Count - 1);
         }
         return Mathf.FloorToInt(scaled_perlin);
     }
 
 
 
     void CreateTile(int tile_id, int x, int y)
     {
         /** Creates a new tile using the type id code, group it with common
             tiles, set it's position and store the gameobject. **/
 
         GameObject tile_prefab = tileset[tile_id];
         GameObject tile_group = tile_groups[tile_id];
         GameObject tile = Instantiate(tile_prefab, tile_group.transform);
 
         tile.name = string.Format("tile_x{0}_y{1}", x, y);
         tile.transform.localPosition = new Vector3(x, y, 0);
 
         tile_grid[x].Add(tile);
         
     }
 
 
 }
 
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

126 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

Related Questions

How to scale perlin noise 2 Answers

[C#] Wondering what is amiss with my 1D Perlin Noise Terrain Generator? 2 Answers

Generating Chunks of Ore Using Perlin Noise 3 Answers

Always same result from Mathf.PerlinNoise() 2 Answers

How to create a perlin noise heightmap with the values being the highest around a point? 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