We use cookies for improve the user experience, for session storage and for statistical purposes.     Accept
Login

Voxel Terrain 2D Manual

Remember Voxel Terrain 2D is still under development and this manual is still incomplete; we are working quite hard to complete it! :)

If you have any questions, suggestions or if you need help, we will be happy to answer you at uas@gargore.com.



Index

This index can be used to navigate faster and easier to the different sections of this document:


First Steps (^ back to index)

Import the package using the asset store or assets / import package / custom package, better on an empty project the first time.

Create an empty GameObject and attach to it the script Assets / Plugins / Runtime / Terrain2D / Scripts / Terrain2D.cs

Now you can see at the inspector several properties.

First of all you need to find Data Width and Data Height properties and define the width and height of the terrain layer. Try first small numbers like 32 or 64 to start familiarising and then increase them slowly because bigger numbers requests more memory.

Once you have configured the width and height the terrain will be drawn and you can start to look at the other properties.

Their are divided into several groups:


Creating your First Terrain (^ back to index)

First of all, You need to apply the steps in the previous section (at least attach Terrain2D.cs to an empty GameObject) and, if you didn't make it yet, you NEED to find Data Width and Data Height properties (in Terrain2D script inspector) and define the width and height of the terrain layer. Try first small numbers like 32 or 64 to start familiarising and then increase them slowly because bigger numbers requests more memory and depending on your configuration can cause slowdowns.

After that you will see that the size of the drawed outline (in white) enlarges. Now you can start drawing by marking Editor Enabled property.

Draw something by using mouse with LMB pressed while in the Scene View. You can only draw inside the Terrain2D boundaries. To finish you can simply select one of the unity stardard tools in the top-left corner of the unity window (move camera, move object, rotate object, scale object) to disable the editor mode.

Move or rotate the Terrain2D GameObject for example. After that if you want to continue editting you will need to check again the Editor Enabled property. Note that checking Editor Enabled automatically disables the Unity tool. It is normal and it is required because Terrain2D needs to take control of the input.

By default you will be digging a fully filled terrain. To fill temporarily some digging that you made before hold left shift while drawing with LMB.

You can change brush mode or size by using Editor properties.

When you are ready, press play or run and the mesh will be generated.

You can edit also in runtime but usually you will use the dig/fill public methods of Terrain2D for digging or making explosions. Both methods are easy-to-use with three simple parameters: Vector3D position (a 3D vector with the world position, let z = 0 for 2D games), float brushsize (radius of the brush, or of the explosion), float ammount (the ammout of material to add or remove: each data handles values between 0 and 1).


Adding a Background Layer (^ back to index)

For the moment we didn't add a background wall geometry. If you simply mark Layer Render Empty property the wall geometry will be generated in the same material and depth that the front material.

For changing this simply create a new GameObject, attach another Terrain2D and select as Layer Master property the Terrain2D that you already had. Enable Layer Render Empty and disable all other layer render properties and layer collide walls.

Now if you run again the scene you will see that both gameobjects have generated the complementary geometry. Stop the scene and move the newer gameobject in the z axis if you want to add depth.

Finally remember that Layer Slaves could not be editted: use the Layer Master for editting and do not set Data Width or Data Height: if you set it the generated data will be discarded as long as the modified layer is set as an slave.

You can add INDEPENDENT layers at different depths by repeating the steps in CREATING YOUR FIRST TERRAIN chapter (without linking them as slave).

Finally each layer can have one slave or one master (and not both fields can be filled). If you link several slave-chain-Terrain2D then the behaviour is not warrantied.


Adding Water (beta) (^ back to index)

Water is added into a separate layer (not master, not slave). But water interacts with terrain. For marking which Terrain2D use as terrain set the Layer Water Reference field. You must select a independent or master Terrain2D.

Usually you must set Water Terrain2D at the same or bigger x2 x3 or x4 Data Width and Data Height than the reference. Both GameObjects should be aligned and scaled so its aparent position and sizes match, otherwise you will get strange visual effects.

For enabling the Terrain2D as water renderer you must enable the Layer Render Water property (and usually disable all the others). Also select a water/transparent material (otherwise the water will be rendered as the same terrain material that was selected. Use the Material property for select the material that you want to use.

Finally for adding a water generator or drainage attach a new empty GameObject and attach TerrainWater2D script. Select the target Terrain2D (usually should be a Water layer manager. Select the radius (more radius, more water and size) and the source rate or drain rate (usually 0 or 1 are good values to start).

The water generator will infere from its relative position from the water layer the cell in which the water should be generated or drained.

Check that the depth positions of the different layers are ok. Water layer must be placed between the background and the master layer, otherwise it will be beyond them and therefor hidden.

It is time: change the material of the water layer (look for a property called Material and select a different material, for example you can select example0w material, included in the examples and which is blue-translucid. Draw some figures and place the water generator and drainer, run the scene and you should have a small river flushing.


Properties Description (^ back to index)

Here is the list of all the properties:

Usually you should use only the properties explained in the tutorials, but sometimes you will need to use one of the additional properties. Save always a backup of your scene before starting to test properties that you didn't test before or whose real impact you don't know.

This list includes also some properties that are only availables when some conditional compiling flags are enabled. Other properties are only available in the latest betas. If you don't see any of these properties on your library version, probably it will not be important: it's better that you don't change conditional compiling because some flags enable beta code which can be not very stable in your version.


Script interface (^ back to index)

Terrain2D class exports some public methods that ease the task of terrain editting via script.

Get a Terrain2D instance reference using GameObject.GetComponent or by defining a Terrain2D property on your own script.

Once you get a terrain2d reference you can call dig or fill methods. Both have 3 parameters: Vector3 pos, float brushsize and float ammount.

pos is a Vector3 position in the 3D world. Terrain2D itself will convert the position into the corresponding position in the 2D plane. You can pass also a Vector2 as it will be converted automatically.

brushsize is a float which is the size of the brush. The bigger the size, the bigger the dig or fill area.

ammount is the ammount of terrain to remove or add. It is like the "opacity".

You can call dig or fill passing directly your script's gameobject position, example: calling terrain2D.dig(transform.position, 1.0f, 1.0f) will remove terrain.


Future Additions (^ back to index)

This manual will include in the future more sections. Meanwhile please feel free to ask you what you want mailing to: uas@gargore.com.