- Home /
World Generation with Interesting Terrain
Okay, so I'm in a bit of a tricky situation. I'm making a game which some might describe as a Minecraft ripoff, and Im having some trouble with world generation. As it stands, I can procedurally generate what amounts to a big, near-perfect cube of various blocks with no noticeable hills, mountains, or other terrain.
This is, obviously, a problem.
What I'm basically looking for is a way to have the generation of blocks slowly taper off at certain points, dependent on the height and whether or not the previous layer had any "air blocks" (empty game objects which serve as filler for empty spaces during generation), but I'm not married to that notion. Any help or better ideas would be appreciated. I'll post the code I've got, so you know how everything's working so far, but be warned, it is a mess.
public var blocksToGen = 100;
public var blocksGenned = 0;
public var rowsGenned = 0;
static var worldBuilt : boolean = false;
var rowOffset : boolean = false;
var xPos = 0;
var yPos = 0;
var zPos = 0;
var lowerBlocks = new Array();
var upperBlocks = new Array();
var blockToGen : int = 0;
var layersGenned = 0;
public var maxHeight = 100;
public var seaLevel : int;
public var heightOffset : double;
var replacementBlock : int = 1;
function Start () {
lowerBlocks[0] = blackstone;
lowerBlocks[1] = stoneBlock;
lowerBlocks[2] = dirtBlock;
lowerBlocks[3] = airBlock;
lowerBlocks[4] = airBlock;
lowerBlocks[5] = airBlock;
lowerBlocks[6] = stoneBlock;
lowerBlocks[7] = stoneBlock;
lowerBlocks[8] = stoneBlock;
lowerBlocks[9] = stoneBlock;
lowerBlocks[10] = stoneBlock;
lowerBlocks[11] = stoneBlock;
lowerBlocks[12] = stoneBlock;
lowerBlocks[13] = stoneBlock;
upperBlocks[0] = blackstone;
upperBlocks[1] = airBlock;
upperBlocks[2] = airBlock;
upperBlocks[3] = airBlock;
upperBlocks[4] = airBlock;
upperBlocks[5] = dirtBlock;
upperBlocks[6] = dirtBlock;
upperBlocks[7] = dirtBlock;
upperBlocks[8] = dirtBlock;
upperBlocks[9] = dirtBlock;
upperBlocks[10] = dirtBlock;
upperBlocks[11] = dirtBlock;
upperBlocks[12] = stoneBlock;
upperBlocks[13] = stoneBlock;
while (layersGenned <= maxHeight) {
while (rowsGenned < blocksToGen * 2) {
while (blocksGenned < blocksToGen){
if (yPos == 0){
blockToGen = 0;
} else {
blockToGen = Random.Range(1,14);
}
if (layersGenned <= seaLevel) {
Instantiate(lowerBlocks[blockToGen], Vector3 (xPos, yPos, zPos), Quaternion.Euler(Vector3(90, 0, 0)));
} else {
Instantiate(upperBlocks[blockToGen], Vector3 (xPos, yPos, zPos), Quaternion.Euler(Vector3(90, 0, 0)));
}
blocksGenned += 1;
xPos = xPos + 2.15;
}
blocksGenned = 0;
zPos = zPos + 1.89;
//zPos = zPos + 1.89;
if (rowOffset == false){
xPos = 1.075;
rowOffset = true;
} else {
xPos = 0;
rowOffset = false;
}
rowsGenned = rowsGenned + 1;
}
layersGenned = layersGenned + 1;
yPos = yPos + heightOffset;
rowsGenned = 0;
blocksGenned = 0;
xPos = 0;
zPos = 0;
}
}
EDIT: So what I'm thinking right now is to add a second layer of randomness, basically generating a random number from 1-4 and adding an additional block if the number is 1, or something like that. Unless I get any better ideas, I'll be going with that.
Your answer
Follow this Question
Related Questions
Add perlin noise to blocky terrain 0 Answers
Help with placing and destroying blocks 1 Answer
15625 blocks are making my game lag? Increase performance? 3 Answers
Minecraft world generation in JavaScript 0 Answers
map generation issues 0 Answers