Skip to content
Snippets Groups Projects
Commit 429f3176 authored by Chang, Ryan's avatar Chang, Ryan
Browse files

Octaves and terrain gen complete.

parent 5c9d8401
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -312,6 +312,7 @@ GameObject:
- component: {fileID: 1796874586}
- component: {fileID: 1796874585}
- component: {fileID: 1796874584}
- component: {fileID: 1796874587}
m_Layer: 0
m_Name: Terrain
m_TagString: Untagged
......@@ -379,3 +380,27 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1796874587
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1796874583}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7b1479ee951becd49bdec6fec1a6da0c, type: 3}
m_Name:
m_EditorClassIdentifier:
terrain: {fileID: 1796874585}
type: 0
octaves:
- amplitude: 0.5
frequency: 0.01
- amplitude: 0.1
frequency: 0.05
- amplitude: 0.01
frequency: 0.1
refresh: 0
xSamples: 513
ySamples: 513
......@@ -5,18 +5,60 @@ using UnityEngine;
[System.Serializable]
public struct Octave
{
float perlinScale;
float perlinHeight;
public float amplitude;
public float frequency;
}
[System.Serializable]
public enum NoiseType
{
Perlin,
Simplex,
Celluar
}
public class TerrainGenerator : MonoBehaviour
{
public Terrain terrain;
public NoiseType type;
public List<Octave> octaves;
public bool refresh;
[Tooltip("How fine grain the generated terrain will be. Larger values = more precise.")]
public int xSamples = 1000, ySamples = 1000;
private void Start()
{
float[,] heights = new float[xSamples, ySamples];
//float xRes = (terrain.terrainData.size.x / xSamples);
//float yRes = (terrain.terrainData.size.y / ySamples);
Vector2 startPerlinPos = RNG.GetRandomVector2(-xSamples, -ySamples, xSamples, ySamples);
foreach (var octave in octaves)
{
for (int x = 0; x < xSamples; x++)
{
for (int y = 0; y < ySamples; y++)
{
heights[x, y] += Mathf.PerlinNoise(x * octave.frequency + startPerlinPos.x, y * octave.frequency + startPerlinPos.y) * octave.amplitude;
}
}
}
terrain.terrainData.SetHeights(0, 0, heights);
}
private void Update()
{
if (refresh)
{
refresh = false;
Start();
}
}
}
......@@ -5,6 +5,7 @@
"com.unity.ide.rider": "3.0.15",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.mathematics": "1.2.6",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.4",
......
......@@ -62,6 +62,13 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.mathematics": {
"version": "1.2.6",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.0.2",
"depth": 2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment