Profile image

if(JetFly.longStoryShort(1) == "I made a procedural terrain generation in Unity!"){reader.wonder();}

4,109 JetFly  6.0 years ago

I wanted to do something unusual to me (working on a space simulator) and decided to do something with these terrains.

A Unity Terrain in work.

These terrains are mainly used to create game levels with an open-world (sort of).But assigning variables like Terrain.terrainData to a terrain data (Captain Obvious) allows switching to other level without loading screens. So, I decided to generate those TerrainData's with a Perlin Noise (That's a noise with random illusion, like world generation in Minecraft, Seems random, but in fact worlds have seed values, and when you create two worlds with the same seeds, they will be the same.)
Here is a kind of this thing, but here we do have a Multiplier, X seed, Y seed and height*. So, entering these 4 values instead of randoms will result in exactly equal terrains, no matter what you do.

Okay, ready with theory, let's do that!
It's a pretty easy code, but it's hard to get what does what.So comments are required to navigate in such of code.
First of all, we generate random (absolutely random) values for our seed variables, except of width and length of the world.

Then we generate a heightmap of a perlin noise function.And then just applying it to our terrain using Terrain.terrainData = our heightmap.
P.S.The method doesn't involves heightmap images, it uses an array of height floats instead.
The result you already seen.

Thanks, JetFly.

  • Log in to leave a comment
  • Profile image
    4,109 JetFly

    @randomusername no, you can download only assets that have been uploaded using your version and below, but nowadays almost all assets that can work in unity 4 are shared with unity 5 or 2018. But updating only for 6 png's is a stupid decision

    5.9 years ago
  • Profile image
    4,109 JetFly

    @randomusername When i want juat a skybox, it wants me to update.Update just for 6 .png's!6 PNG FILES, omg you need an update! (I use Unity 4.1.2 because of PC limitations)

    5.9 years ago
  • Profile image
    4,109 JetFly

    @randomusername I hate Unity just because this asset store

    5.9 years ago
  • Profile image
    4,109 JetFly

    @WNP78 aaah, missed one "=" sign
    it needed to be JetFly,longStoryShort(1) == "blahblahblah"

    6.0 years ago
  • Profile image
    Dev WNP78

    @JetFly I'm just on about the title xD

    6.0 years ago
  • Profile image
    4,109 JetFly

    @WNP78 but it works
    random.range is a method too
    But you can assign to it

    6.0 years ago
  • Profile image
    12.1k Starbound

    Cool stuff

    6.0 years ago
  • Profile image
    12.1k Starbound

    @WNP78 I was thinking the same thing, it couldn't be an array so what would it be? lol

    6.0 years ago
  • Profile image
    Dev WNP78

    Also you can't assign to the result of a method xD

    +1 6.0 years ago
  • Profile image
    Dev WNP78

    I played around with procedural terrain a while ago. I never finished it because I moved on to other projects first. I had fairly decent speed on a PC with the terrain generating in the background. Here's some images of what it's like. Note that the biomes are quite small. They are scaled down so I don't have to spend ages flying between them across tiles to see them all. Also the mountains look pretty horrible :\

    +1 6.0 years ago
  • Profile image
    4,109 JetFly

    @PhantomBladeCorp Yes, that's pretty easy, but settings are really mad.
    P.S. Made on Unity 4.2.0

    6.0 years ago
  • Profile image
    47.8k Phantomium

    I've actually seen a tutorial on YT where a guy explained this very well and even showed it off on spot. It's not as hard as it seems, though the setting up part left me a bit in the air, I have to admit :)

    6.0 years ago
  • Profile image
    4,109 JetFly

    Also, I had idea on generating infinite world's by changing seed in real time.But, as I says before, generation takes five seconds.

    +1 6.0 years ago
  • Profile image
    4,109 JetFly

    @randomusername @Roswell
    Terrain generation on Android will be very battery consuming and long, because even on PC generation takes around five seconds.

    If u are masochist, then yes, it's possible.
    And no, I'm not going to upload it, because maybe yes.
    Android definitely not, I don't want to download Eclipse and mess with input to generate an APK once in my life.
    Sorry guys.

    6.0 years ago
  • Profile image
    7,256 Roswell

    Two questions :1. are you going to upload it? :1. and will the map be for Android?

    6.0 years ago