I have an issue/bug with chunks generating the Perlin noise strangely. I have put the code below as well as a screenshot of what the outcome is in play mode. I was wondering if anyone has come across similar issues as I cannot work out what is wrong and why the chunks are not seamlessly connecting.
I appreciate the time that anyone spends looking at this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Noise : MonoBehaviour
{
Color[] colorMap;
Texture2D texture;
public Transform[] chunks;
public int dimension;
public float scale;
private void Start()
{
foreach (var chunk in chunks)
{
Renderer rend = chunk.GetComponent<Renderer>();
texture = new Texture2D(dimension, dimension);
texture.wrapMode = TextureWrapMode.Clamp;
texture.filterMode = FilterMode.Point;
colorMap = new Color[dimension * dimension];
rend.material.mainTexture = texture;
SetPixels(new Vector2(chunk.position.x, chunk.position.z));
}
}
public void SetPixels(Vector2 offset)
{
for (int x = 0; x < dimension; x++)
{
for (int y = 0; y < dimension; y++)
{
float xCoord = (x + offset.x) / scale;
float yCoord = (y + offset.y) / scale;
float sample = Mathf.PerlinNoise(xCoord, yCoord);
colorMap[y * dimension + x] = new Color(sample, sample, sample);
}
}
texture.SetPixels(colorMap);
texture.Apply();
}
}