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

Modeling and other updates... 7/21/2018
More modeling...
Modeling and other updates... 7/20/2018
I created another color level and more models...
Updates... 7/19/2018
I created a script that rotates, scales, or positions an object using a sin() function...
Updates... 7/15/2018
Just a cute screenshot of a NPC-to-Player interaction.
Models 7/15/2018
I created a few more trees and a couple more animated abstract objects.
Models 7/14/2018
Here's a short animated GIF showing the motion I've added to the new models.
Models 7/13/2018
I created a few new models for low-poly environments...
Colorful Low-Poly Game updates... 7/8/2018
I made a few updates to the low-poly project...
Maze Generation 6/11/2018
Since the mesh-generated walls don't have textures, I tried to place some posters on them...
Maze Generation 6/9/2018
Updates to the maze generation experiment...
Site created and maintained by kreediddy. © 2010-2018. kreediddy.