Terrain 101

When asked to join the team, I’d never actually heard of Unity3D. I had some experience using the Source engine (Created for Half-Life 2 and used for the Left 4 Dead and Portal games) and Blender (A free, open-source 3D modelling application), so I at least had a good grasp of environment design and modeling.

So I poked around in Unity for a few weeks and, after creating the ‘Dakota’ model –  that’s the helicopter you fly in the game –  I decided to fall back on my Blender knowledge to tackle the terrain. And so, based on a sketch of the environment, I blocked out the terrain, generated a heightmap* and imported the terrain to Unity. Turns out this was a mistake!

* A heightmap is basically a black and white image used to convey height, with black as the lowest point and white as the highest.

Let’s try again…

Having rushed into the process  a bit enthusiastically and not really gotten the results we wanted, it seemed like a good idea to be a little more logical about the whole thing. And so, whilst walking the dog, I drafted up a “Terrain Action Plan” for my own benefit. I’ve added most of it with my notes below:

1. Create height map in Blender with following properties;

  • Dimensions 2048 + 256 units on either side

When using the Unity physics engine it’s generally advised to use 1 ‘unit’ as 1 metre, so at 2048×2048, our prototype map is roughly 2km x 2km. On the heightmap image, a single pixel also represents 1m.

The 256 extra units were later removed – the idea was to have 256 units all the way around the map to sculpt into mountains or impassable terrain to stop the player leaving the map without using invisible walls.

  • Create bounding boxes

These bounding boxes represent the maximum geometry height to avoid blocking the camera’s line of sight to the player, and the maximum height the player can fly. They also gave me a good sense of the map limits and where the ‘barriers’ could be added.

  • Sculpt Peaks up to 100 units high
  • Majority of terrain to be below 30 units as to allow Dakota to pass over.

The peaks were added to a height that we wanted to look impassable, so they were nice and high.

The last point was added prior to the altitude controller code we decided to include. You can’t adjust the height you fly at in the game as it’d be way too many buttons, but the game controls it for you.

  • Plenty of flat areas.
  • Camera Settings: orthographic, render size = 4097×4097 px, file = tiff 16bit

The flat areas were obviously there as the ‘play area.’ The idea was the edit this in more detail later when we have a better idea of how the level would play out.

The camera is set to orthographic to remove any perspective effects and create the image of the terrain in 2D. I created the heightmap image at 4097 x 4097px for additional detail, so each pixel now represented 0.5m squared. The image was saved as a .tiff 16bit image, which allows for a smooth range of grey scale, and so a smooth terrain.

2. Additional Detail in image editing;

  • Set resolution to 2049px

At this point we’d tested the 4097 x 4097px heightmap in Unity and the resolution was way too high. Oddly this also caused all sorts of lighting problems and jagged terrain, so we quartered the image size and everything ran silky smooth without losing any detail that we needed.

There’s a technical reason for setting it to 2049px, we weren’t just being awkward!

  • Add pock marks and craters
  • Flip whole image horizontally

This was to add some extra detail to the flat areas of the terrain and make it more interesting than a completely flat area. The image is flipped due to the way Unity imports the heightmaps – we’re not really sure why this happens!

  • Save as 16-bit RAW file

RAW is the file format that Unity (and lots of other tools) use for heightmap files.

3. Export RAW to Unity;

  • Create new terrain; Terrain size 2560x2560x100.
  • Terrain heightmap resolution needs to match .RAW file resolution.
  • Apply ‘terrain_bump’ material in terrain properties
  • Apply textures as normal

These are mainly related to the settings we used in Unity to import the terrain and get it to the right scale, etc.

More details!

Unity has a great terrain editing tool for adding small details (or creating a rough terrain quickly) that I used for tweaking the terrain at this point. It’s basically a set of paint brushes like Photoshop that lets you ‘paint’ height changes onto the terrain.

If you paint small changes with certain brushes this gives an uneven look to the terrain, like you’d expect to see in real life. It’s also much easier to edit certain areas from the heightmap without having to go through all these complicated steps again.

Surprisingly this helped a lot with the creation of the terrain. There were a few tweaks to make such as reducing the dimensions of the RAW file, but on the whole the end result is a step in the right direction.

blendersm

Leave a Reply

Your email address will not be published. Required fields are marked *