Description

Live Chat: Discord.
Get the latest builds: Patreon.
Get Mods here: Reddit.
Public Version for Heroine Rescue Team (v0.51): Here.
Download for Heroine Rumble is at the Heroine Rumble page.

Saturday, July 21, 2018

In Game Terrain Editor - Part I

Been working on a fairly major feature - an in game terrain editor (that can place/remove objects too). It's not 100% done yet but enough of it is working already to start writing a post about it.

But before that, I want to take a detour and talk about some design decisions first. First of all, I know from the beginning that making an actual real time 3D game is alot of work, and my resources are very limited. So I tried hard to reduce complexity and optimize workload whenever it makes sense to do so. One of those decisions is on how the terrain/environment is done.

I decided to go with a tile/voxel terrain system (think Minecraft) rather than the "regular " 3D mapping system. While the regular method allows one to create terrain with far greater level of detail than a tile based system, it also takes a lot more work - something that I don't know if I'll have the time to do. Whereas I think I can do a reasonable job with a tile based system.

I am not quite satisfied with the blocky Minecraft terrain, so I set out to implement smooth voxels. And that I did:


However, using only smooth voxel led to problems. For example, it is impossible to create a sharp edge (so it cannot be used to create walls) and it is extremely noisy. So eventually I created a system that can support 3 different type of blocks: terrain blocks, smooth blocks, and regular cube blocks.

But that creates another problem: because the game's terrain system is unique (afaik), I don't actually have a visual tool to create the terrain with. So far, I managed to mostly sidestep the issue with a heavy emphasis on procedural generation (the dungeon and encounter map). The village is done with a lot of pain. I had to basically write in a textfile where each object is, reload the game, eyeball how close I get, re-edit the textfile and try again. It was a valiant attempt but clearly something better is needed.

So hopefully that gives people a idea of the motivation behind creating an in game-terrain editor. To summarize:

  1. As an development tool to create environment with. I want a better Village. I want a better Bandit Camp. I want a better Ludas Lair, and so on.
  2. As an experimental tool to get experience on how to implement the base building part. Afterall, base building is just terrain-editing, but with constraints.
  3. Finally, as something for modders and other who might be interested to mess around with.
Here I am going to go in some detail on how the tool works, if this is not something that interest you, feel free to skip.

In order to bring up the editor UI, you need to acquire a "terrain_editor" item and "use" it. For example, dragging it to the hotbar and press the corresponding hotkey. It looks something like this:



The editor is divided into tabs. Currently, there are Terrain, Block, Tile, Object, and Misc tabs. While the editor is open, most regular game actions and hot keys are disabled. The right mouse button and "Use" on the item itself toggles between locking and unlocking the mouse. Unlocked mouse is used to operate the editor UI, and locked mouse is used to confirm editor action, similar to how the rest of game operates.

The Terrain Tab:

The Terrain tab is used to modify the terrain blocks. The terrain is basically a height map, in voxel form. Essentially, the game stores a height on each (X,Z) coordinate and the terrain is generated from that. Compared to smooth voxels, it tends to generate smoother geometry, but because it is 2D, it is not possible to use it to generate ceilings or buildings with multiple floors. Hence, the operations on the terrain are Raise, Lower, and Smooth.



Raise increase the elevation of the terrain, as demonstrated here.
There are also 3 modifiers:
Size increases the radius of affected zone.
Strength determined how much to raise/lower the terrain by.
Curve is kinda hard to explain, so it's probably better to use pictures instead.

Curve = 0.0



Curve = 0.5

Curve = 1.0


Lower is the reverse option, that decreases elevation. For example, if you want to dig a pit: (using Size = 10, Strength = 3, Curve = 1)


Finally, there is Smooth. Smooth calculates the average height of the selected area, and then cause each tile in the area to move towards the average. Recommended to use a low strength, medium to high Curve value for the best results. Here Smooth is used to create a ramp into the pit:


Next up we have the Blocks tab. The block tab is used to create/remove individual blocks:

Place creates blocks. On size of 1, the behavior is identical to Minecraft. But its also possible to use higher Sizes to create a bunch of cubes at once.


Remove is the opposite process that removes blocks.

And finally, we have Smooth blocks if cubes isnt your thing. For example, a sphere:

It's possible to create caves with a combination of "Place"ing and "Remove"ing smooth blocks:


At this point, some observant readers might ask: with smooth voxels, why do we need terrain blocks as well?

Good question. It's what I thought so too at the beginning. However, there are some problems with a only-smooth voxels approach. The first is that the geometry generated by smooth voxels is noisy. It might look smooth from a distance but it actually may contain lots of small bumps and ridges. If a character tries to walk on it, she may get stuck. Whereas the geometry generated by terrain blocks is much smoother in comparison.

The second problem is that path finding with only smooth voxels is too computationally expensive. With a height map (terrain voxels) , path finding is a 2D problem - expensive, but doable, whereas with smooth voxels, it is a 3D problem, which is very expensive to calculate.

So here is the rule of thumb: use terrain block to denote areas where characters can walk on, then use smooth voxels for things like obstacles and ceilings that cannot be done with a height map only approach.

Also, the Block tab cannot be used to modify the terrain, and the Terrain tab cannot be used to modify blocks. (But you can certainly raise the elevation such that the terrain will engulf the blocks)

Thirdly we have the Tiles tab. The tiles tab is used to modify the texture/image of existing blocks. Kind of like of what the hoe does, except faster. For example: use it to convert grass to dirt.

I should probably mention here the "cheats" options as well. Currently, under the Misc tabs, there are 2 options - Gravity and Collision.

When Gravity is disabled, you can fly! Woohoo! Space key flies upwards and Ctrl keys flies downwards. For example, if you really really want a minimap, you can!


The collision toggle, well, toggles collisions. Useful if you accidentally entomb yourself and such.

And I also feel obligated to mention that any "interesting behavior" resulting from enabling cheats are all "unintended features." Bugs with the tool itself, of course, send a bug report. But if enabling cheats causes things like AI don't know what to do with an aerial unit, those are all "features" :P

Finally, we have the Objects tab. This tabs is used to place/remove "dumb" objects. For example, if we want to place houses in the dungeon because, why not?


The Facing option changes the rotation.
The Scale options changes the scale.


And of course, we can remove objects with the remove option - because building houses in a dungeon is probably not a good idea (it really isn't)


Phew, that's a lot of text for part I. So I'll end it here. There are still a few things I need to do - the save/loading of map files being one of the big things that is still WIP; the ability to load models - probably will be using a similar method with custom clothing, but static models should be much common and easier to handle than skinned models; finally, the ability to load new tiles/images as well, such as this, to make everything prettier:







2 comments:

  1. Woow Nice dude! You're a really hard working guy! I have respect for that. Can't wait until the online playable version comes out! Cheers

    ReplyDelete