Polytegy map tiles generation
I want to release alpha version as soon as possible and greatest challange so far was creating world for the game. In our vision RTS should look great from above and have appeal of dense natural glades and tunnels through foliage. Here I will share some thoughts on our attempts given that we create game using unity.
What we have tried:
- Prefab Templates - it was easiest method. There were prepared prefabs with environment objects setup from editor. Straight forward to preview the output and see how the effect of forest will finally look like. Random only took care of choosing either resources prefab, trees or big unbreakable trees. It can be seen in short video we made.
- Light Templates with editor- second attempt we were talking about with designer included templates loaded from file with only important data. Prefabs for templates were to heavy and we were looking for a way to reduce amount of displayed objects. Prefabs would only be used for environment objects like resources, trees and so on. Since designer worked full time in his daily job and we had no clue how to design editor the idea was dropped. To much effort for such task.
- Parametric design - another approach was made by our friend who in pretty smart way visualized the glades using Rhino and Grasshopper and then rendered all after export to blender. The potential of prototyping power in these tools was overwhelming but it had it's own environment and we couldn't figure out the simple way of integration such data with Unity. I tried implementing the steps of Grasshopper algorithm but effects didn't looked the same. By the way, procedural and parametric generation is not the same as far as I am concerned - If anybody has nice explanation of the differences it would great to hear it!
- Cellular Automaton - I have used such method before. It is as simple as generating random noise and "smoothing" it with cellular automaton algorithm. Cellular automaton is like post processing for noise and for each cell it returns value based on amount of adjacent filled cells. Results is nice and naturally looking pattern ideal for caves and so on. Simplest way to control the patterns is to draw on cells like on bitmap after noise is generated. Works every time!
Cellular Automaton implementation
Implementation is fairy straight forward and in this case can be broken down into 6 stages:
- Create Editor for the map tile so we can faster check how random patterns will look even without launching the game.
- Generate random noise - it is simple PRNG random generator, not even perlin or something fancy.
- Draw path according to metadata of map tile - we want to be sure that units can pass from one tile to another.
- Draw empty space in the middle of tile - adds the feeling of forest glades.
- Run cellular automaton to smooth the random noise on tile and add more natural feeling to it.
- Run cellular automaton once more but performing different operation. This time it increments cells if it has enough filled adjacent cells. Those cells will be used to create unbreakable environment and force player to explore the maze.
In game screens with even positions centered to cells
Legend: cubes are breakable, cylinders are unbreakable.
In game screens with positions randomized to fit cells
Here you can see whole process in one gif. All parameters will be further tweaked until I am happy with results. Cell's value is used to choose which type of prefab to draw from: 0 (black) is empty space , 1 (grey) are breakable and resources, 2 (white) are unbreakable environment objects.