VoxelWorld Level Generation
Generate our level design through code using VoxelWorld
VoxelWorld is our system for building out grid based blocks in your world. In this game we will dynamically generate terrain to play around. The goal is to spawn walls around our map and randomly place cover blocks.
Install Survival Package
The survival package has default block assets to use in a voxel world. Lets install it into our project so we don't have to make blocks manually.
In the top menu select "Airship -> Packages"
Drop down "Add Package", enter "@Easy/Survival" and click Add Package

Create The VoxelWorld
Right click your scene, "Airship -> VoxelWorld". This creates the VoxelWorld gameObject with all the components needed to sync your VoxelWorld across the network.
On the VoxelWorld gameObject make sure block defines contains "CoreBlockDefines". If it doesn't you likely need to add the Survival package again and manually apply CoreBlockDefines to VoxelWorld.

VoxelWorld is optimized in c# to manage a grid based world. In Typescript it is suggested to use the World.ts class which gives you easy to use TS wrappers for VoxelWorld.
Now lets write a class to generate some blocks!
in VSCode Make a new Typscript file called "TopDownBattleLevelGenerator.ts"
Open it up and create a new class
When the component is enabled we will grab our reference to the world and run our generation code
Now lets take a look at each of the generation functions. The first one is GenerateBase(), which creates blocks at the center of the map. You can see its easy to manually place a block at a specific position with a specific block type defined by SurvivalBlockType.
You can also spawn blocks in one batch using the PlaceBlockGroupById. In GenerateWalls we fill an array up with block positions and a parallel array for the block type.
Lastly we will generate some obstacles to randomly place around the map
Since we have made this class extend AirshipBehaviour, we can add it to a ScriptBinding component and modify the variables in editor. Create a game object, add a ScriptBinding component and select "TopDownBattleLevelGenerator"


Last updated