Doing an endless runner style map and spawning tiles ahead of the player.
I’ve got an array that it spawns from. But it has a tendency to throw the same tile 4 times in a row occasionally. Fairly annoying. They are large tiles and recognizable so I really want to minimize the repeating.
I tried a shuffle but not sure I’m using it right. I tried before and after the loop.
I really noticed no difference between having the shuffle and not.
I’ve got 8 tiles atm and I get a lot of 2,3 and 4 of the same tiles. Maybe 50% of the time I am getting 4 unique tiles.
I ran into a similar issue when spawning waves of enemy units in a randomized manner. What I ended up doing was adding weights to each enemy type. You can do something similar in this scenario as well.
Each of the 8 tiles can have equal weighting at the beginning. But every time you use up a tile, you reduce its weighting, which then slowly increases (till it reaches the default value) over time/update cycles. If you absolutely do not want repetition, you can even set the weighting down to zero after a tile is used. This will make sure that the tile does not repeat itself in adjacent iterations.
Have you got an example of how to do that. I’m afraid that’s getting beyond my knowledge.
I’m trying remove item and remove from index. While they do remove stuff from the array they both seem to be working on the index. So some of the items can still respawn as their index number is just resetting each time.
Still repeats some though. Not seeing much difference than from before really. Ran through a bunch of spawns and kept numbers.
If I spawn 4 tiles out of 8 (I was spawning 7 when I took this screen) I still get repeats 50% of the time. That’s about the average I had before. Of course I am probably doing this wrong.
’ Forest tiles ’ is an array of 8 tiles.
‘empty tiles’ is a completely empty array.
I know I am just getting a random number to spawn, out of the random shuffle I just made (wasted). But I can’t figure out how to plug the output array into the spawn actor without the GET.
If you want to allow for a non-unique element, iterate 3 times instead of 4, and add another element from the All Tiles list. This way you will have 3 unique and a small chance (eyeballing it at 20-25%) for a single repetition.
At first the game is level up mode. So it starts with 4 tiles, after the player levels up it will increase. When all levels are complete it will just be an endless runner.
So at first with only 4 tiles, if I am getting 2-4 of the same exact one it’s really noticable (large tiles so the scenery stands out. it’s not just 200 tiles with random objects where everything kind of looks the same anyway).
Once it’s ‘endless’ I will have ‘zones’ so it will spawn green tiles for a little while and by the time the index of green tiles is empty it will change to an index of red tiles, etc… eventually cycling back to green tiles.
My example works. Generate the array of classes first and only then spawn the tiles; here it looks as if you were doing it in the middle of the loop. If in doubt show us how you wired the whole thing up.