Procedural Generation Tiles
I'm trying to create an infinite map made out of two types of Giant Tiles, The first one would be empty, and the second one would have a random amount of between 1 and 4 mesh components (depending on Tile's position) with random scale and location(in the bounds of each tile). They would alternate like on a checkerboard.
So far, I've been able to spawn new tiles ahead of the player as I approach them and destroying the ones that are left behind, but I've been using some sort of grid where every cell is identified by a number.
At the moment the grid needs to have a finite amount of cells set along with a grid width. NumberOfCells/GridWidth == GridWidth && NumberOfCells % 2 == 1 (NumberOfCells needs to be odd ) For example: NumberOfCells = 81, GridWidth = 9 With these parameter it creates a grid where all cells in a diagonal have odd numbers associated with them and the next diagonal line in parallel have even numbers (like the black(0/odd) and white(1/even) on a checkerboard)
I created a Vector Array where the Index corresponds with the NumberOfCells and the value correspond to the cooordinate in the grid. I'm keeping track of the character's position and tracking in which cell he is in a variable. I created variables named after the Cardinal Directions. They contain the cell number of the cells around the player. They are calculated using the CharacthersCell, the GridWidth and simple math. I am using these to spawn new tiles and destroy the ones behind everytime the character move to a new tile.
I don't know if its worth mentioning but the character won't be moving diagonally.
I don't think this method would work in an infinite version of this so I would like your help to figure out what should I change so that my level is no longer limited. I also wanted to know if I was on the right track or if what i'm doing is way too complicated for nothing. And last thing, it would be very helpful if could have some way of identifying each tile. Like if at these coordinates it would be Tile # 73647632 so that I could destroy it but then, if I come back later, i could spawn the same one.
I tried to include as much information here but let me know if printscreens of blueprints would be better!
Thanks a lot!
asked Dec 15 '17 at 07:27 PM in Blueprint Scripting
Its a bit messy what you describe but here some very generalized things.
You can represent 2D Coordinates in a 1D array its called row and colum major order, you can look it up there should be enough information around the internet. You can see a example of that in this Training video https://www.youtube.com/watch?v=mI7eYXMJ5eI
You also have to think about Chunks of Data because you obviously cant create infinity. What you can do however is to generate a Bunch of 50x50 Grids as example. So if you move out of one of these you can generate another one in front of you and delete the one behind you. It is very similar to the way you generate the Cells on a grid but this time you generate Chucks.
If you want you can use a TMap if you want to store Key Value Pairs. Your Key would be the Cell/Chuck cordinate (I recomand IntVector instead of Vector) andt the Value would be the Cell/Key refference.
You can do a lot with simple Math alone like for example calculate the Index of a Cell/Chuck based of a Worldlocation (Your character Location, Click location etc.) make those Functions. Its no Magic its just a bit of Math you can do on Paper.That Index you can use to access your Array or TMap.
Use Random Streams to generate your random Values. That has the benefit that you always get the same Random values again with the Seed you used in the same order. So if you delete a Chuck and want to generate the same one again if you move back Reset the Stream, use the same seed and you will get 100% the same randomly generated Chunk back.
You can generate a Seed for your Streams in a smart way. Generating random 4 digits (once at start or per Level) + the cordinate of your chunck. Example: 5555000 (initial Chuck) 5555100 (next Chuck in X direction) and so on.
I think that info should be enough to solve whatever Problems you have right now. Or at least tell you what to lookup in more Detail.
Good Luck and Have Fun =)
answered Dec 15 '17 at 09:08 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here