We are trying to archive random infinite chunk generation.
We are currently facing a problem, due to memory optimisation reasons we have to handle generation by each client individually. The problem that we are experiencing, is that we don’t know how to ensure that each client has the same chunks generated.
We already tried:
random.new() and random:NextInteger()
math.random() and math.randomseed()
Please let me know on how you would make each client generate the same chunks at the same coordinates, thank you.
I am not sure how your system worked, but you should be able to make a system by setting the random seed with “math.randomseed”, using a number unique to each client. (UserId)
After setting the randomseed, generate it by using “math.random”.
math.noise gives an output on a rough interval of [-1, 1]. In order to use the value to directly pull a chunk out of a folder, I would shift the interval to [0, 1] by adding 1 to the output and dividing that value by 2. Optionally, you can use math.clamp to force the new value between 0 and 1. You could then multiply this value by the number of children in your folder and using math.ceil, so that this value cannot be 0.
After all this, you can use the value to index a chunk from within the folder and do what you will with it.
It depends on how you’re doing it, to which I really have no clue, so I don’t know why direction matters.
If I were generating my chunks, i’d base everything on the coordinates.
As someone else stated however, a math.noise approach would likely be best. If you’re still looking for an answer, it may best to specify how you’re generating your terrain.
I simply use variatons of math.noise(x coordinate, z cooridinate) when im generating terrain, with some other maths ofcourse to generate decent terrain. I’ve never tried infinite terrain or a chunk based approach though.
Ah sorry, spent some painful days working through a terrain generation algorithm so just assumed lol
If you base your Random.new(seed) seed on the center coordinate of the chunk then, for every player, the random output will be the same for each chunk. I’m assuming your using random to generate a number from which you’ll pick from a chunk.
chunks = chunkfolder:GetChildren()
--after checking if and where the chunk needs to be loaded then
random = Random.new(chunklocation.x.."|"..chunklocation.y)
chunkToLoad = chunks[random:NextInteger(1,#chunks)]
Should in theory pick the same chunk for each location every time, ofcouse im greatly assuming how your doing things.