Randomly generated map from sprites

Hi, I’ve just started working on a 2d project. Top down not side scroll.
What I’ve been trying to do is randomly generate a map from sprites such as dirt, grass, sand and water.

So far I’ve managed to select a specific sprite (dirt) from a tileset and fill a paper tile map component by going through each row and column in the construction script.
Here is the bp:

Here is the filled tile map:

What I would like to do is add random patches of grass, sand and other terrain types within this space. Kind of like minecraft… but 2d.
I’m sure this is possible but I’m not sure about how I would go about doing it.
I can get terrain types to spawn on single random tiles but not in groups.

Also I would ultimately want to use edges of terrain types. Like the transition from one terrain type to another.
Similar to the following image that I found on google:

Does any one have any ideas?

Thanks!

Hey! @

This should work, but I can’t test it. You basicly have an array, where you put your index numbers from your atlas. It will grab the length of the array, randomly choose a number in it and pass it on. The branch will take care of the generation of the patches, where you can choose with a variable, how many tiles should a patch contain. After the patch limit is reached, the loop will reset and restart itself moving on with a new tile and patch generation. I have to admit it is very primitive, but it should get you going :).
You just need to incorporate this into your main loop and kill it, if the map is completely done:

Hi, Thanks for the response! I’ll give this ago when I get home from work.

I’ve also had an idea of using randomly generated heightmaps and using the “height” information or the gradient from black to white to set what tiles go where.
I can make height maps outside of ue4 and import them in. but I was wondering if there is a way of randomly generating them with in ue4?
Obviously I still have no idea how to get the info from the height map and use that info to place tiles in specific places. But I’m just throwing some ideas out in case something clicks in someone’s head.

I’ve read that height maps cannot be read at runtime because of collisions and such but no info on randomly creating them within ue4.

As I said I’m going to try what you’ve suggested and play around but any other info or input woul be greatly appreciated.

@

What do you intend to do with it? Or rather what are you expecting out of this system?

I may be able to come up with some solutions, but I would need to exactly now, what you are trying to do with it :).

Well I’ve been massively inspired by the game forsaken isle,
Video here:

Basically a 2d minecraft but on an island. I would like to make a living 2d world. Now I have been using ue4 for quite some time now but never for a 2d game so this should be pretty exciting to get working.
Moving the player, Interaction and inventory systems is what I’m already capable of doing… A beautiful random map I am not capable.

So I would like the map to be randomly generated as previously stated. The player will be able to change tiles on the floor by using various tools such as a shovel which would basically turn a grass tile in to a dirt tile.

With the random map generation I would like to figure out a way making it like the following:
1.PNG
Not like this:
2.PNG

So if the player were to dig or change a tile, the edges of the tile would change depending on the surrounding tiles.

In regards to using a height map I have found this: https://gillesleblanc.wordpress.com/2012/10/16/creating-a-random-2d-game-world-map/

This is pretty much what I want to achieve. But random with those nice tile edges like the previous image shows.

It’s going to be a lot of work but totally worth it.

If you could assist in anyway then that would be amazing!

Also I would like to add, depending on what terrain tiles are down would decide what type of foliage would be placed on those tiles.

If you want the tiles to look like that. you need to do bitwise operations on the level data in order to generate the correct tile number. Look up “bitwise auto-tiling”.

Further more, a game like that, is probably not generating the entire level on a single map layer, it’s probably generating layers and bitwising them.

Ohh that looks like it is exactly what I’m trying to achieve. It will be a lot of help. Though I am going to need to figure out a way of doing this using blue prints as coding is not my strong point.

Ok so I’ve started off with trying to get random patches. I’m not getting the best results so far.
This is my BP:

These are the results I’m getting:

So this is where I’m at so far. :s This is going to be quite a challenge I think especially when trying to figure out bitwise auto-tiling.
I’ve found this link which explains bitwise auto-tiling pretty well. I’ve arranged my sprites and added them to an array but putting this together in Blueprints is wrecking my brain!

Anyone got any ideas?

Thanks!

I am going to necro this post as it is partially relevant to one my projects. Of the three pictures, with the patchy grass I noticed they had the same amount of tiles places per index number ie index 1 places 4 grass tiles, index 3, places 5, index x = place x number of tiles, it may help with the more patchy natural look. I may be using the wrong terminology for the solution.