Jump to content
  • Advertisement
Sign in to follow this  
keinegutennamen

Unity Run-time Terrain Generation (long time coder, first time game dev)

This topic is 2074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been developing for 25 years and suddenly had the urge to create a game for fun.  So I am completely new to game development.  After doing a little research I have settled on Unity as the platform I will use.

 

I want to be able to dynamically generate, at run-time, a terrain for my little game.  I have seen a few toolkits that generate terrains that can be used with Unity but these are done at design-time.

 

I have also seen a couple of posts here from people saying they are using different kinds of noise maps to generate their terrain on the fly.  I think this is the direction I want to go but I am not sure.

 

I am looking to generate a small playing area.  It won't be growing so I don't need to worry about continuous generation.  It's just a 1 time generation (and eventually a save and load) as their little world.  It would be small...maybe 2000 x 2000 units.  I would like it to be somewhat smooth in the way elevations work (i.e. I don't want a minecrafty type world but a smoother appearance).  The camera will never be first person but will instead be looking down on (hopefully) the full map from above.

 

My questions are:

  • Terminology - Instead of feeling my way through this, can someone give me a basic rundown of the terminology used for this type of work (specifically terrain generation)?  That way I can research how to accomplish something like that (right now I don't even know what to search for)
  • Noise Maps or Voxel Terrains - Are noise maps the way to go (read recommended) for generating terrain on the fly?  Or would a Voxel Terrain be better?  Again...don't want minecraft type terrains.  Better methods?
  • Types of Noise Maps - If noise maps are the way to go, does anyone know of a breakdown somewhere of the different kinds of maps used and what types of terrain they typically generate?  I think I remember someone saying Perlian was a type....not sure...don't remember.
  • Sample Code - Does anyone know of any sample code out there that will show how this is done. I don't care what language it is in (as long as it isn't something crazy like Prolog or Lisp).  Something that is used by Unity is, of course, preferred (C# or Java I guess) but not necessary as I can easily translate.

 

Any help pointing me in the right direction (especially terminology) is greatly appreciated!

 

Share this post


Link to post
Share on other sites
Advertisement

One way that can turn out pretty cool is to randomly select a dividing line across the height-map, and raise everything on one side a little bit while lowering everything on the other side. Repeat a few thousand times.

Share this post


Link to post
Share on other sites

Some basic methods are:

* subdivision (what Erik described),

* sampling a noise function (like Perlin noise), and

* using FFT to convert Gaussian noise to the frequency domain, filtering and using FFT again to reconstruct the terrain.

 

If you want to include rivers in your terrain, it gets tricky, but there are methods for that too. A Google search for "terrain generation" comes up with lots of good resources.

Share this post


Link to post
Share on other sites

Hello,

 

If you want your terrain to be deformed, formed, etc at runtime then you might consider something using the Marching Cubes algorithm. You can find some pretty decent resources on using that with terrain generation. That would be a voxel-like approach. If you don't need your terrain to behave like that, then you can use height maps and generate a mesh based on that map. If you are going to use Unity, the API has the TerrainData class that are used to create Terrain objects programmatically. I think there is even some built in stuff to use height maps. I know you can do it at design time, so there might be a way to do it programmatically with little custom effort. 

 

With a little searching, you will find an implementation of Perlin noise done for Unity in C#. It was included in one of thier procedural example projects and will help you create height maps in code. Hope that helps!

Share this post


Link to post
Share on other sites

for what its worth, one of my first terrain generators worked like this:

generate a small height-map, initially filled with random numbers;

recursively upsample and add a small amount of random noise each time;

when the final target size has been reached, generate terrain from it.

 

at every upsample step, the size of the height-map was essentially doubled, and these small noise values will often "add up" into forming more larger scale features.

 

 

later on I moved to the use of Perlin noise and similar, but this was mostly because I wanted to do infinite terrain and incremental world generation.

however, for a long time memory usage mostly limited it to a small area.

 

later I moved back to a finite world size (this time, 64 x 64 km, or 65536 x 65536 meters).

in this case, the world is basically a big flat plane with wrap-around, and with some special logic in the terrain generation to cause it to wrap, and where going over the edge basically causes the player to teleport to the other side.

 

I had considered a few times possibly bringing back the recursive upsampling strategy mostly to help better create large macro-scale features (with Perlin noise more used for small and medium scale features), but thus far haven't done so.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!