Search Unity

Assets 2D Tile Based Procedural Map Generator

Discussion in 'Works In Progress - Archive' started by Deleted User, Nov 1, 2017.

  1. Deleted User

    Deleted User

    Guest

    2D Tile Based Procedural Map Generator
    upload_2017-11-21_5-44-33.png
    As the title suggests, this is a tool I am building to use procedural generation and object pooling to create large tile maps for world maps or 2D tile based games. The below is a minimum viable product.

    Feedback is more than welcome! If this sounds particularly useful for your game, let me know; while this is a tool I am planning on using in my game, I am considering posting it to the Asset Store.

    Source of the tiles used for prototyping: David Baumgarts Tiles

    • Data storage solely consists of playerprefs (which is friendly to many platforms)
    • Utilizes object pooling; increases memory requirement but zero instantiations occur during runtime
    • Enables/Disables sprite rendering based on whether the tile is in use (deployed) or not in use (object pool) to enhance performance
    • Randomizes selection of tiles that have very similar parameters; avoids mountain ranges looking exactly the same
    • Currently implements adjustable perlin noise, other algorithms possible for the future (would love feedback!)
    • Makes use of your selected tiles to generate everything; customize the heck out of your tiles and attach the parameter helper script
    • Each tile is a Game Object! That means you can child say, a particle effect, to a tile and it will be pulled in with the tile on map generation
    • Automatic adjustment of the sprites "Order in Layer" by row so that sprites properly overlap. Tall Mountains should not be hidden beneath the tile above them for example!
    • (Future plan) Z-Axis controls so that you can make procedural terrains using awesome isometric tiles!

    Automatic tile layer ordering means we can keep mountains from "getting trapped under" the tiles above them, for example. This also means if you have a character moving around the board, they can use the layering information from the tile they occupy to tell what their own layer should be (i.e. a character's feet would be hidden by the tip of the mountain below).
    upload_2017-11-4_10-10-27.png

    Here's a full screenshot showing the different stages of workflow from left to right; see the steps below for a breakdown!
    upload_2017-11-11_22-17-18.png

    Workflow
    1. Select your tile objects on the left (in the hierarchy). These are the objects the generator will then use. Each object has a helper script that details the parameters of the tile (elevation, civilization level, precipitation, etc.) In addition, if tiles have very similar parameters (think multiple different tiles representing mountains), it will group them together and then randomly make use of that group to serve a tile. This is how the above visual differences in terrain are displayed; there's actually 4 different ocean tiles and about 5 different mountain tiles shown. They are all still considered mountains for the sake of generation.

    upload_2017-10-31_21-11-12.png
    2. Setup the total size of your map, as well as the buffers on the X and Y axes in order to customize the buffer between tiles to your specific tile size. This means you can use tall, or wide tiles (doesn't have to be exactly square).

    3. Experiment with the pool size to optimize the number of pooled tiles to meet the dimensions of your map. When the player starts a new game or clicks "random map", or even selects between larger oceans or rockier maps, this pool is used to serve up those maps at runtime and stores using playerprefs.

    View attachment 252948
    4. Perlin noise is the first successfully implemented noise function for adding tiles. Much more can be added in the future to customize generated tile maps.


    Feedback Requests:
    • How does this seem useful for you? (What would you use this for)
    • What do you think would be helpful in terms of customizing your map? Custom variables, new proc gen algorithm support?
    • Is there a different data structure that you advise using (or adding support for)?
    • Are biomes important for you, and if so what kind of biomes?
    Sincerely,

    SageSingularity
     

    Attached Files:

    Last edited by a moderator: Nov 21, 2017
    dgbaumgart likes this.
  2. Deadlyapples

    Deadlyapples

    Joined:
    Dec 30, 2013
    Posts:
    54
    This is neat :D
     
  3. schysoid

    schysoid

    Joined:
    Jul 4, 2013
    Posts:
    1
    Hi SageSingularity
    this looks like a neat tool
    I was looking for a way to generate a new world map for the player every time he creates a new game
    do you think this could be used in that way?
    cheers!