- Home /
Question by
Munkkeli · Jun 02, 2014 at 07:37 PM ·
mathproceduralchunk
Cross chunk details
I'm trying to generate trees, rocks and other details on my chunks. Currently the system only works when the chunk is placed on all positive coordinates (x > 0 && y > 0).
Like you can see from the image, the right side (x > 0 && y > 0) works well but the left side (x < 0 && y > 0) is wrong on the X coordinate.
The system works by generating a blob of stone based on the random seed, it also calculates the blobs for each chunk next to the current chunk so the blobs from the nearby chunks can continue to the current chunk if needed.
I'v been working to fix this issue for couple of days now, and if someone has a better way of doing this I would gladly hear it.
Here are the current functions used to get the decorations for each chunk:
// Get decorations for a chunk
private static void GetDecorations(int X, int Y, Decoration decoration, List<Decoration> decorations, ChunkGenerator gen) {
int size = World.world.chunkWidth;
// Get decorations for all the nearby chunks
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
GetDecoration(X + (x * size), Y + (y * size), decoration, size, decorations, gen);
}
}
}
// Get decorations for one chunk
private static void GetDecoration(int X, int Y, Decoration decoration, int size, List<Decoration> decorations, ChunkGenerator gen) {
System.Random rnd = new System.Random((int)(Mathf.PerlinNoise(X / 10f, Y / 10f) * 100000));
for (int i = 0; i < decoration.density; i++) {
if (rnd.Next(0, decoration.rarity) == 0) {
int x = X + rnd.Next(0, size), y = Y + rnd.Next(0, size);
decorations.Add(new Decoration(decoration.block, decoration.maxSize, decoration.minSize, decoration.density, 0, decoration.function, x, y, 138, rnd.Next(decoration.minSize, decoration.maxSize + 1)));
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613150618im_/https://answers.unity.com/themes/thub/images/avi.jpg)