• Advertisement
Sign in to follow this  

Unity How to procedurally generate 2d top down world?

Recommended Posts

So I am trying to figure out the best way for me to go about procedurally generating 2d top down world (like RimWorld) for a game I am working on. From everything I have read it seems like I would want to use noise algorithms for generating the world however the kind of math that seems to be required for this type of procedurally generation is not a strength so I am trying to find libraries that will handle most of the heavy lift as far as the math / algorithms go however the results I have been able to generate so far have been unimpressive.
Right now I am just trying to be able to generate the main world land not worrying about small things / resources like tress, flowers, rocks, ore, etc right now.  Want I am looking to be able to do right now is just:
  • Generate a map of X by X size that is surrounded by a certain impassable tile (deep ocean, unbreakable rocks, etc.)
  • Be able to generate a number of different biomes that have logical sense (have a beach biome only next to the ocean, have an oasis biome only within a desert biome, etc.)
  • Make the terrain look somewhat irregular so that each map generation does not look too similar and the biome shapes should be quite varied
I have been trying to use a Unity implementation of this library : https://github.com/Auburns/FastNoise_CSharp :  and I am guess I am using it wrong or something as the maps I generally filled of a bunch of oval shapes within ovals shapes. The few tutorials I could find on the topic either 1. Go into building the noise generating algorithm itself which while at a basic level I could probably do but I would be completely screwed if I had to extend that algorithm to what it would probably need to be for my end goal or 2. Talks about stuff at such with no code examples or anything and at such a high level I have not idea what they are talking about. I have no issue with using the data that is generated from the algorithms to be used for generating the world, I just know that I am not the person to actually generate those algorithms themselves.
Are there any good tutorials that have decent code examples about working with 3rd party algorithm libraries (C# would be ideal since that is the language I use with Unity) to generate maps of this nature?

Share this post

Link to post
Share on other sites

What are you generating exactly? It looks like you are assigning regions of a 2D map to belong to different "biomes", but how do the abstract biomes translate to concrete environments? For example, are you placing different plants as scenery in different biomes?

Also, why do you insist on using noise functions? If the main constraints in your procedural generation are about what biomes should or should not be adjacent, why don't you start from a planar graph of adjacent biomes and turn it into a map by giving each region the appropriate shape, elevation and other features?

Share this post

Link to post
Share on other sites

Many years ago, I wrote some blog entries about using my own noise library to generate procedural islands:




An example:



The entries are quite dated now, as my noise library has moved on quite drastically from what it was back then, but the concepts still remain the same.


The idea is that you use different types of functions to generate the result you desire. The islands in those articles use a distance function as the base, which is distorted by a noise fractal to give the island shape. Other various functions and fractals are layered on to create mountains or hills, to delineate areas of mountain and hill, and so forth. It can require a great deal of experimentation so that you know what the results of certain functions will be, and can predict what things will look like. 

Share this post

Link to post
Share on other sites

I find erosion-modelling to be what makes noise-terrain look like real terrain. It's not too difficult to do and gives great results. Check out this paper for a good explanation and some images to get what it's about: https://www.dropbox.com/s/kqv8b3w7o8ucbyi/Beyer%20-%20implementation%20of%20a%20methode%20for%20hydraulic%20erosion.pdf?dl=0

Share this post

Link to post
Share on other sites

Thanks for the tips all. I ended up continuing to use the noise generator for the general map and was able to find a tutorial that was dumbed down enough for even me to understand (at least enough) on how to create a circular mask with randomization in it in order to have the map completely surrounded by water / beach. I am sure I will have more questions in the future as I am sure I am going to need to do more / better generation but at least this gives me a map that is usable for the time being.


Thanks again.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By bryandalo
      Good day,

      I just wanted to share our casual game that is available for android.

      Description: Fight your way from the ravenous plant monster for survival through flips. The rules are simple, drag and release your phone screen. Improve your skills and show it to your friends with the games quirky ranks. Select an array of characters using the orb you acquire throughout the game.

      Download: https://play.google.com/store/apps/details?id=com.HellmodeGames.FlipEscape&hl=en
    • By Manuel Berger
      Hello fellow devs!
      Once again I started working on an 2D adventure game and right now I'm doing the character-movement/animation. I'm not a big math guy and I was happy about my solution, but soon I realized that it's flawed.
      My player has 5 walking-animations, mirrored for the left side: up, upright, right, downright, down. With the atan2 function I get the angle between player and destination. To get an index from 0 to 4, I divide PI by 5 and see how many times it goes into the player-destination angle.

      In Pseudo-Code:
      angle = atan2(destination.x - player.x, destination.y - player.y) //swapped y and x to get mirrored angle around the y axis
      index = (int) (angle / (PI / 5));
      PlayAnimation(index); //0 = up, 1 = up_right, 2 = right, 3 = down_right, 4 = down

      Besides the fact that when angle is equal to PI it produces an index of 5, this works like a charm. Or at least I thought so at first. When I tested it, I realized that the up and down animation is playing more often than the others, which is pretty logical, since they have double the angle.

      What I'm trying to achieve is something like this, but with equal angles, so that up and down has the same range as all other directions.

      I can't get my head around it. Any suggestions? Is the whole approach doomed?

      Thank you in advance for any input!
    • By khawk
      Watch the latest from Unity.
    • By GytisDev
      without going into any details I am looking for any articles or blogs or advice about city building and RTS games in general. I tried to search for these on my own, but would like to see your input also. I want to make a very simple version of a game like Banished or Kingdoms and Castles,  where I would be able to place like two types of buildings, make farms and cut trees for resources while controlling a single worker. I have some problem understanding how these games works in the back-end: how various data can be stored about the map and objects, how grids works, implementing work system (like a little cube (human) walks to a tree and cuts it) and so on. I am also pretty confident in my programming capabilities for such a game. Sorry if I make any mistakes, English is not my native language.
      Thank you in advance.
    • By Ovicior
      So I'm currently working on a rogue-like top-down game that features melee combat. Getting basic weapon stats like power, weight, and range is not a problem. I am, however, having a problem with coming up with a flexible and dynamic system to allow me to quickly create unique effects for the weapons. I want to essentially create a sort of API that is called when appropriate and gives whatever information is necessary (For example, I could opt to use methods called OnPlayerHit() or IfPlayerBleeding() to implement behavior for each weapon). The issue is, I've never actually made a system as flexible as this.
      My current idea is to make a base abstract weapon class, and then have calls to all the methods when appropriate in there (OnPlayerHit() would be called whenever the player's health is subtracted from, for example). This would involve creating a sub-class for every weapon type and overriding each method to make sure the behavior works appropriately. This does not feel very efficient or clean at all. I was thinking of using interfaces to allow for the implementation of whatever "event" is needed (such as having an interface for OnPlayerAttack(), which would force the creation of a method that is called whenever the player attacks something).
      Here's a couple unique weapon ideas I have:
      Explosion sword: Create explosion in attack direction.
      Cold sword: Chance to freeze enemies when they are hit.
      Electric sword: On attack, electricity chains damage to nearby enemies.
      I'm basically trying to create a sort of API that'll allow me to easily inherit from a base weapon class and add additional behaviors somehow. One thing to know is that I'm on Unity, and swapping the weapon object's weapon component whenever the weapon changes is not at all a good idea. I need some way to contain all this varying data in one Unity component that can contain a Weapon field to hold all this data. Any ideas?
      I'm currently considering having a WeaponController class that can contain a Weapon class, which calls all the methods I use to create unique effects in the weapon (Such as OnPlayerAttack()) when appropriate.
  • Advertisement