Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Procedural grid-based world generation

Discussion in 'Scripting' started by z37, Oct 6, 2014.

  1. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    Hi to everyone!
    When working on a game, I came up with a problem of procedural generation of levels. In my case, It should be an infinite level(almost) with some specific rules of placing the objects. It also should be grid-based.
    So, i am looking for some help in giving the right instructions how to start, and what to learn(perhaps some articles or books). To be more specific, i want to know the basics of procedural staff, how to save and store those generated levels, how to visualize it then in unity and how to deal with those parts, that a player doesn't see and has no possibility to access as they are too far.
    I understand that the scope is to vast, but i will be glad to any useful information on this subject! Thank you!
     
  2. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    If you dont plan on modifying the terrain (by the player) at runtime, making your procedural generation deterministic is the key to 'saving' your data. It is fast and compact: you dont save it at all! Generating with the same input gives the same output. Thus, if you only store an input value (most of the time an int, which is the world 'seed') you should be able to reproduce everything from that single value. If the player is able to make adjustments in the game, you need to save those as well.

    The first thing I would look at is Perlin noise, value noise or Simplex noise (or noise in general). there is a bit of a misunderstanding. Some people think value noise is the same as Perlin noise. This is not true and it may be worth it to see what the difference is. You dont need to know the actual implementation details of it, but you should know how to utilise it. Just treat it like a black box, which gives different outputs based on its inputs. Learn how to control those inputs to get the desired outputs. Then, generate a heightmap out of that for a specific tile. Load tiles as the players move around and unload the generated data of those that get far away.

    Learn how to create meshes from code, that is, create vertices and triangles from the heightmap you generated, then learn about triplanar texturing to texture the terrain.

    There is lots of information to find if you simply google those terms (perlin noise, procedural terrain, triplanar texturing etc etc). This should give you a general direction of what's involved.
     
    Last edited: Oct 6, 2014
  3. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    I am really greatful for your reply! If i understood, those methods are suitable for random terrain generation or so. When developing my problem, i came up with the idea that my case is more sophisticated. I realised that i need procedural content generation in level, for example usage of the methods that certain content position that subordinates some definite logics(something like how the treats and onsticles will be positioned in my world space). The problem facilitates as for a start, i just want to generate it on a flat surface and in some kind of a grid-based way. And the user interacts with this content.
    I have started to read a book, http://pcgbook.com/ i hope it will help somehow, and i have one more question, how to store the information about content? should it be some kind of a matrix, and if yes, will it be efficient to store information about a big world almost infinite?
    Thank you very much, looking forward to hearing from you!
     
  4. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
  5. z37

    z37

    Joined:
    Feb 13, 2014
    Posts:
    29
    Thank you, I hope it will be helpful for me!