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

Prototyping 11/24/2017
Several updates to the new Android prototype.
Prototyping 11/23/2017
I setup different lighting to mimic the previous shaders I was using.
Prototyping 11/22/2017
Screenshots from another scene...
Prototyping 11/21/2017
Here's a couple quick screenshots.
Prototyping 11/21/2017
More work on the Android prototype...
Prototyping 11/19/2017
Worked on some custom controls for the Android.
Free 3d Pumpkin Model 10/20/2017
In the spirit of Fall, I created a 3d model of a pumpkin!
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.
Site created and maintained by kreediddy. © 2010-2018. kreediddy.