I need to generate tile data for an island based rpg, my goal is have something that looks like this (mountains not required):
For the past few days I have been trying to figure out a satisfactory way to generate tile data that will give me varied and natural islands, such as in the example above.
I've tried using Unity's Mathf.PerlinNoise but the results are far too random, and I can't see a way to get it to generate a single island.
Using LibNoise I was able to get slightly better results, although the generation seems to be significantly slower and perhaps better suited to 3d terrain. Similarly however, I can't see a way to set the Octaves/Frequency/etc, so that I get a nice single island each time.
While there are a fair amount of resources online for perlin/noise in general, it mostly seems to be aimed at 3d terrain and height, where I simply have a 2d array of int for my tile data, that maps to either water, sand or grass and needs to be generated in such a way that sand/grass are grouped together logically to form an island.
Any help would be greatly appreciated!
Answer
One thing I've done in the past for island shapes is to use perlin noise minus a circular shape. It usually produces one big island and some little things off on the side. You can use flood fill or smoothing to remove any small noise.
Here's a demo (flash) that I wrote for this question.
For each location (x, y)
in the noise bitmap, compute the distance from the center, normalized so that the bitmap is 2x2:
function distance_squared(x, y):
dx = 2 * x / width - 1
dy = 2 * y / height - 1
# at this point 0 <= dx <= 1 and 0 <= dy <= 1
return dx*dx + dy*dy
Location (x, y)
is part of the island if perlin_noise(x, y) > 0.3 + 0.4 * distance_squared(x,y)
. In the demo you can vary the two constants to see the effects you can get.
I don't think these islands look quite the way you want but this technique might be useful for you in combination with other techniques you're using.
No comments:
Post a Comment