- Home /
Semi-Random terrain generated at runtime.
Hi. I need a terrain tool (or tools) capable of generating random terrain with some fixed features. Like flat areas to facilitate building cities, at certain spots on the map.
There seem to be a lot of tools that can randomize terrain to then be saved as a fixed terrain object, but i want this to happen every time a new map loads in the game.
Thanks.
~Axil
Yeah it appears as though the terrain toolkit can randomize the map like i need. I'm just not sure if it, or any other tool can take that random map, and modify it to add some flat areas in set positions..
I would think that if you have the capability to generate the random map, a second pass that added some static features should be possible using the same kinds of methods, no?
I feel like my lack of experience in this area is making my question vague, and harder to answer than it needs to be.
Let me try and summarize what i want to do in a little more detail.
After the game has loaded, but before the player enters the map, i want a random terrain of a set size generated. I would like to be able to utilize a tool with features like Terrain toolkit has, where the randomization is done in such a way to make believable hills, mountains, valleys, etc, within ranges set by me.
again before the player enters the game, i want that random map to be modified so that i can add flat places on certain portions of that map, by x,y,z, coordinate. I need these places to be flat so i can put prefab structures on them during the course of the game. In doing so, the height of the terrain has to be taken into consideration somewhat, as a flat terrain at y=0, cored into a mountain would be unplayable.
$$anonymous$$aybe this isn't technically "run-time" generation? I don't need terrain popping up during game-play, i just want it to be randomized each time a map is loaded in, and still have the control to make certain sections of the map "unrandom".
Answer by Eric5h5 · Sep 05, 2012 at 11:04 PM
You can generate any kind of terrain you want, and do anything with the results. What you're doing is generating a 2D array of floats to use for the heightmap, so you can make flat areas just by writing the same value to a given area of the array. Here's an incredibly cheesy "random terrain generator" that makes some random bumpy ground, with some randomly-positioned flat areas:
function Start () {
var res = 513;
var tData = GetComponent(Terrain).terrainData;
tData.heightmapResolution = res;
var heights = new float[res, res];
for (var i = 0; i < res*res; i++) heights[i%res, i/res] = Random.Range(.49, .51);
tData.SetHeights (0, 0, heights);
var flat = new float[50, 50];
for (i = 0; i < 50*50; i++) flat[i%50, i/50] = .5;
for (i = 0; i < 10; i++) {
tData.SetHeights (Random.Range(0, res-50), Random.Range(0, res-50), flat);
}
}
Answer by Owen-Reynolds · Sep 05, 2012 at 06:53 PM
From a programming side, a random terrain generator doesn't care it you run it on level load, or in the editor. At some point it's going to make a 2D height map, and another with the texture values, which you can do use however you want. So, you should be able to reuse any random terrain code you already have.
But real-time random terrain is a lot of work. Off-line, a human can run one, then clean up the impossible-to-play/boring/dumb-looking parts. Look at random dungeons -- they have all these 2x2 "rooms", crazy long winding hallways, "level is one giant room" levels (really 8 rooms that got randomly jammed together.)
Your answer
Follow this Question
Related Questions
Changing Replacement Shaders at Runtime 2 Answers
Modify a mesh at runtime 0 Answers
Procedural Terrain? 3 Answers
Need help with randomizing starting location of terrains 0 Answers
Paint Terrain Texture From Vector3 List 0 Answers