home     support     info  


Creating Environments in Unity: The Backstory - Posted on: 8/27/2016   [Uncategorized]

I had an idea for a game that would feature many different environments, but it was too ambitious - I didn't have time to create everything by hand, so I wondered...

"Would it be possible to generate the environments randomly?". I knew it would be challenging, but if possible, it could save hundreds of hours of production time.

I wasn't interested in creating an entire universe like the game No Man's Sky. Though the idea of procedurally generated environments was very appealing and it would be perfect for what I needed. Well, I didn't figure out how to generate infinite terrains, but I did figure out how to make a large terrain randomly.

Unity has great built-in tools for creating terrains and I found a resource which demonstrated how to create them via script. There are many variables - it's quite complicated - it took me several months to customize and really wrap my head around the technical aspects.

The basic concept...
  • Declare all the terrain settings.
  • Create the terrain data.
  • Create the terrain object.
  • Fill the terrain object with the terrain data.
Skybox, Lighting, Fog, Wind, Particles, and Camera FX - these are all things that will enhance the scene and give life to the environment.

The techniques...

Here are some examples of the conditions and techniques I'm using to create the environments:
  • Terrain size is generally 2048x2048, with matching detail map for thick grass, and alpha map at half size.
  • 4 different alpha maps (terrain textures), which are drawn according to the terrain's slope and height: ground, hill, snow cap, and water basin.
  • 3 different grass details using 3 random frequencies and sizes. Height constraints to keep the grass from being drawn near shoreline or above snow caps.
  • Only rocks and grass are placed in low height (water basin) regions.
  • Gradient fall-off formula applied to terrain height data for an "island effect".
  • Water plane, Particles, and Perimeter are all scaled automatically to match the terrain size.
In addition to the terrain functions, I made a separate function that handles normal game objects - it's for objects that have scripts or shaders that can't be attached to the terrain. Like, dust or wind particles.

Other customizations...
  • Terrain material supports specular lighting and normal maps.
  • Custom height-map texture is optional.
  • Blur effect smooths out rough terrain edges.
  • Tree prototypes created from dynamic array.
  • "Oasis" option forces trees to be placed only near shoreline.
  • Terrain object colliders are enabled.

Most of the resources used in this project are Standard Assets from Unity. Other textures and 3d models created by me. Additional resources can be found here:

<< Back to main news page

Shooter Game 7/28/2017
One of the early projects I worked on was a top-down shooter game...
New Tablet! 1/1/2017
I got a new tablet!
Updates 11/24/2016
I've been experimenting with different game mechanics and level designs.
Updates 11/11/2016
I've been making my scripts more modular, so they can be shared between projects more easily. For example, I have an underwater script, a wet lens effect, and a mesh explosion script.
New Volumetric Fog 10/12/2016
Got a new fog effect and tested it within several different environments/projects.
New Environment 8/26/2016
Made a few new grass textures and created a colorful fall environment.
New Asset 8/24/2016
I added a new effect to my collection of game assets. It's a screen filter called "Beautify" that en
New Environment Screenshots 8/12/2016
Screenshots from a new environment...
New Shaders 8/3/2016
Worked more on the scene I created yesterday.
New Shaders 8/2/2016
I bought some new shaders and created this scene. It's a mix of custom models and free models.
Site created and maintained by kreediddy. © 2010-2017. kreediddy.