This project is a framework and tool set for procedurally generating a hexagonal tile-based map. It is designed to be used for 4X games such as Civalization & Humankind. The map is generated based on a seed system using Perlin Noise giving the ability to generate pseudo-random maps. The map utilises Perlin Noise to generate its features including, biomes, tiles, structures, rivers and map height. The framework also provides a world wrap system, where the player is able to go off the edge of the screen and the wrap around to the other side of the map, giving the illusion of the map being round.
Programing & Design
2021
Toolset System
Unity, Visual Studio
Grid generation is achieved through a Grid Manager, which, upon initialization, generates a grid comprising chunks. Each chunk is responsible for generating a specified number of tiles. When all the chunks are assembled, they collectively form the complete gridded map.
Prior to map generation, the Grid Manager creates two noise maps, incorporating user-defined settings. These noise maps facilitate the creation of a pseudo-random pattern of floating-point values within the range of 0 to 1. The values extracted from the Perlin noise can be employed to modify and influence the selection of tile types to be placed.
The image displayed below illustrates the outcome following the initial grid generation and the placement of random tiles.
Within the Unity Editor, Biomes are encapsulated as Scriptable Objects designed to hold comprehensive information about each biome. Primarily, these Scriptable Objects serve as repositories for defining the various tile types associated with each biome. For instance, a Desert biome Scriptable Object would encompass a collection of distinct sand tiles.
Upon chunk creation, it undertakes the generation of all the tiles within its boundaries. The chunk iterates through its dimensions, determining the biome for each tile and subsequently assigning the appropriate tile type based on that biome. Once the chunk identifies the tile's designated type, it proceeds to spawn the tile.
The image below depicts the outcome achieved by efficiently managing and categorizing chunks through the biome system.
The River Manager plays a pivotal role in orchestrating the creation of rivers across the map. Its initial task involves identifying specific points on the map where rivers can originate (referred to as maxima) and where they can terminate (referred to as minima).
The River Manager then proceeds to iterate through all the maxima points. During each iteration, the manager evaluates the likelihood of a river spawning based on a percentage chance. If a randomly generated value surpasses this threshold, the river is not spawned, and the loop continues. However, if the generated number falls below the specified percentage chance, the manager identifies the closest minima point to that particular maxima point. At this juncture, both a maxima value (for the river's starting point) and a minima value (for the river's endpoint) are established, paving the way for the river's creation.
The river itself assumes responsibility for charting its path through the landscape, arranging tiles in close proximity along this trajectory while ensuring alignment with the terrain. Initially, the river forges its path using Perlin Worms, akin to selecting a random direction, but with an added layer of control. Users have the ability to adjust a weighting value that influences the degree to which the Perlin Worms affect the direction of the river. Subsequently, the river proceeds to position its tiles to follow the course it has charted.
The image below provides a visual representation of the rivers that have been generated.