# Unity Procedural generation for 2d tile game

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

## Recommended Posts

Hi everyone, i just joined you lovely community.

I need some theoretical help. I'm developing 2d tiled puzzle game, inspired by Minecraft mechanics a bit. Game is about digging down the procedural generated mine, collecting ores, avoiding monsters.

What i have done by now:

[attachment=24773:1.png]

Level is just randomly generated of 3 different terrain types.

What i need help with:

[attachment=24774:2.png]

I'd like to find a way to randomly select groups of tiles, which i will generate as rock type terrain, resembling rocks laying under ground. It should have random shapes and size, but close to circle, and have some distance between zones.

Some my thoughts by far:

[attachment=24775:3.png]

1) Find initial cell

2) For every neighbor of new cell, select this cell with chance depending on distance of this cell from initial cell

3) Recurse for every selected cell

I'd love to hear your ideas about zone selection and its placement around level.

##### Share on other sites

Here's a very simple approach:

Use perlin noise (always a good procedural content generation startpoint ) to generate the map and assign value ranges to certain materials, something like this

0.0 - 0.7 earth

0.7 - 0.95 rock

0.95-1.0 gems

##### Share on other sites

Try to research "Cellular Automata"

##### Share on other sites

Hi,

I've made experiments on a similar problem a while ago (biome placement on a procedural map). One alternative way for solving that type of problems could be to use a constraint solver like Google OR Tools. With OR Tools, you have to express the constraints of your system :

- My domain is a X*Y grid

- I want at most 25% of rock blocks

- Near a rock block there's 75% of chance to have a sand block

etc..

Set the seed, call Solve(), and you get a solution.

The main difficulty is to express the constraints, but I think it could be a very interesting approach, and can give a very good control of the generation.

Anyway, our actual generator is based on Perlin (GPU generation), and it works fine... Just an idea ;)

Edited by DTR666

##### Share on other sites

I'm a bit late on this post, but I'd suggest avoiding Perlin noise and instead using something I like to call OpenSimplex noise: https://gist.github.com/KdotJPG/b1270127455a94ac5d19 (An algorithm I designed for a currently-WIP game because I wanted to avoid both the artifacts of Perlin noise and the patent of 3D Simplex noise)

Perlin noise is an older algorithm that tends to exhibit significant grid artifacts by way of lining all of its features up with the cardinal axes and main diagonals. OpenSimplex noise should provide you with a bit more variety in the directions that your terrain features go. Perlin noise can certainly do some cool stuff, but what you can do with Perlin noise you can probably do better with a more visually-isotropic noise like OpenSimplex.

Perlin (top) vs OpenSimplex (bottom), 2D slices of 3D:

• First is noise(x, y, 0) grayscale
• Next is noise(x, y, 0) > 0 ? white : black
• Next is |noise(x, y, 0)| < 0.1 ? black : white
• Last is noise(x, y, 0.5) grayscale to illustrate that Perlin noise looks "weird" in non-integer slices
Edited by KdotJPG

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 73
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009578
• ### Who's Online (See full list)

There are no registered users currently online

×