I'm making a terrain generator for a game and I need it to smooth down to a float, I've tried a bunch of different things with lerping but I can't figure it out.
I need to stop this from happening by smoothing the height down to 1 once it gets to the edges.
public LevelManager level;
public float noise;
public float oceanNoise;
public float mountainNoise;
public Transform water;
public Transform land;
public void Start()
{
level = FindObjectOfType<LevelManager>();
}
public void Update()
{
float landNoise = noise + oceanNoise;
noise = SimplexNoise.Noise(transform.position.x * level.deatalscale, transform.position.z * level.deatalscale);
oceanNoise = SimplexNoise.Noise(transform.position.x * level.oceanDetailScale, transform.position.z * level.oceanDetailScale);
mountainNoise= SimplexNoise.Noise(transform.position.x * level.mountainDetailScale, transform.position.z * level.mountainDetailScale);
if (noise > level.thresh)
{
land.gameObject.SetActive(true);
water.gameObject.SetActive(false);
}
else
{
land.gameObject.SetActive(false);
water.gameObject.SetActive(true);
}
if (oceanNoise < level.oceanHhresh)
{
land.gameObject.SetActive(false);
water.gameObject.SetActive(true);
}
if (oceanNoise < level.oceanHhresh)
{
land.gameObject.SetActive(false);
water.gameObject.SetActive(true);
}
land.transform.localScale = new Vector3(level.planeScale, Mathf.Lerp(noise*level.height,1,noise) * level.height + level.addHeight, level.planeScale);
if (level.landpos.Contains(transform.position))
{
Destroy(gameObject);
}
}
This script goes on the terrain chunk and it uses its position to find value in noise, the level manager just holds a few settings.
Any help is appreciated, thanks in advance.