You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Tools/MMProcedural/MMGridGenerators/MMGridGeneratorPerlinNoiseG...

35 lines
894 B
C#

3 months ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;
namespace MoreMountains.Tools
{
/// <summary>
/// Generates a grid with a ground floor
/// </summary>
public class MMGridGeneratorPerlinNoiseGround : MMGridGenerator
{
/// <summary>
/// Generates a grid with a ground floor
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="seed"></param>
/// <returns></returns>
public static int[,] Generate(int width, int height, float seed)
{
int[,] grid = PrepareGrid(ref width, ref height);
for (int i = 0; i < width; i++)
{
int groundHeight = Mathf.FloorToInt((Mathf.PerlinNoise(i, seed) - 0.5f) * height) + (height/2);
for (int j = groundHeight; j >= 0; j--)
{
SetGridCoordinate(grid, i, j, 1);
}
}
return grid;
}
}
}