Procedural Generation written in C# which uses Noise textures to generate a random terrain.
Ore and structures can be added to the terrain using custom resources. Structures can be drawn on a TileMap in a new Scene, the child Node2Ds will also generate with the structure (e.g., enemies and items).
Also comes with a script that adds the ability to mine the tiles and add the ore to your inventory. All you have to do is add a Custom Data Layer "ore" to the TileMap and assign it to your ore tile with the name of your ore.
Here's an example of what I made using this system:
- Place all of the scripts into your Godot project
- Add your Player Node to a group called "Player"
- Add a Node2D "WorldGenerator" to your main TileMap node
- Add WorldGenerator.cs to the Node2D
- Right click on the Generation Noise variable, pick FastNoiseLite and configure it to your liking
- Configure everything under the Tiles category (for example Ground Layer is your TileMaps ground layer, same for other variables. If you don't have a type of tiles just turn off "Generate")
- Run the game and it should work if you've configured it correctly.
- Create a folder where you will store your ore resources
- Make a new OreData Resource (Right click > New Resource > OreData)
- Configure your ore
- Atlas coords is the coordinates of the ore in the TileMap image
- Lower frequency makes them spawn in groups more
- Threshold is how often it will spawn
- Add your ore to the WorldGenerator Node under the Ores section (ore at the top will spawn more frequently)
- Create a folder where you will store your structure resources
- Make a new StructureData Resource (Right click > New Resource > StructureData)
- Configure your structure
- Tile Map Scene should be a PackedScene with a TileMap as the root node (draw your structure in that scene, all of the child nodes like CharacterBody2D for example will also spawn with the structure)
- Spawn Chance is seed independent
- Frequency is how close together they will spawn (lower is closer)
- Threshold is how often it will spawn
- Add your structure to the WorldGenerator Node under the Structures section
- Add your TileMap Node to a group called "TileMap"
- Add the WorldGenerator Node to a group called "WorldGenerator"
- Add a Node2D "Pickaxe" to your Player
- Attach the PlayerPickaxe.cs script to it
- If you have a breaking animation TileSet assign the Atlas Coordinates of them in "Break Anim Atlas Coords"
- Add a ShapeCast2D as a child of the Pickaxe node
- You can now mine the tiles
The PlayerPickaxe.cs script contains an inventory dictionary.
- Select your TileMap, open your TileSet and add a Custom Data Layer "ore" with Type "String"
- With your TileMap selected open the TileSet tab (at the bottom of Godot where Output, Debugger, etc is located)
- Select your Ore Tiles (make sure to be using Select instead of Setup), click on any tile and under "Custom Data" write the name of your ore
- Now ores will be added to your inventory in PlayerPickaxe.cs
- To see them you can write GD.Print(inventory); in Process function of the script
You can contact me in my Discord server https://discord.gg/MsF7kN54T7
Just post your issue in the "tech-support" channel and I will try to help as soon as I can.