Hi, I am fiddling with perlinnoise to generate a tilemap using the following code:
i want the map to contain mostly green tiles, and blobs here and there of resources iron , copper etc…
using UnityEngine;
using System.Collections;
public class SpawnGrid : MonoBehaviour
{
[Range(0.1f,100f)]
public float seedX, seedY;
public GameObject gridTile;
public float gridX, gridY, perlinThresholdiron, perlinThresholdcoal, perlinThresholdcopper, perlinThresholdstone;
void Start ()
{
for (float x = -gridX; x < gridX; x += 0.1f)
{
for (float y = -gridY; y < gridY; y += 0.1f)
{
Vector3 spawnPos = new Vector3(x*10,y*10,0);
GameObject tile = Instantiate(gridTile,spawnPos,Quaternion.identity) as GameObject;
SpriteRenderer rend = tile.GetComponent<SpriteRenderer>();
TileController tileController = tile.GetComponent<TileController>();
float perlinNum = Mathf.PerlinNoise(x/seedX, y/seedY);
if (perlinNum < perlinThresholdiron)
{
rend.color = Color.gray;
tileController.isResource = true;
tileController.tileType = ResourceType.iron;
}
else if (perlinNum > perlinThresholdiron && perlinNum < perlinThresholdcoal)
{
rend.color = Color.black;
tileController.isResource = true;
tileController.tileType = ResourceType.coal;
}
else if (perlinNum > perlinThresholdcoal && perlinNum < perlinThresholdcopper)
{
rend.color = Color.yellow;
tileController.isResource = true;
tileController.tileType = ResourceType.copper;
}
else if (perlinNum > perlinThresholdcopper && perlinNum < perlinThresholdstone)
{
rend.color = Color.blue;
tileController.isResource = true;
tileController.tileType = ResourceType.stone;
}
else
{
rend.color = Color.green;
}
}
}
}
}
I can move the seedX and Seedy sliders around to genrate different patterns,
but they are always very repetitive and the resources are always “surrounding” eachother:
how can i change this code so that it generates blobs of resources of random size/shape
(think factorio)
hope you guys understand what im trying to do
