- Home /
Perlin noise for (sort of Minecraft) terrain generator
I want to make a perlin noise in Unity3D in the terrain, I don't know exactly what it means but I guess it makes the terrain mathematical fun!
So here is the code of my terrain generator:
`using UnityEngine; using System.Collections;
public class GenerateWorld : MonoBehaviour {
public int x;
public int y;
public int z;
public Transform prefab;
void Start () {
for(int a = 0; a < x; a++)
{
for(int b = 0; b < y; b++)
{
for (int c = 0; c < z; c++)
{
Instantiate(prefab, new Vector3(a, b, c), Quaternion.identity);
}
}
}
}
void Update() {
if(x < 0) {
x = 0;
}
if(y < 0) {
y = 0;
}
if(z < 0) {
z = 0;
}
}
void OnGUI() {
GUI.Box(new Rect(Screen.width/2 - 350, 10, 700, 25), "The values you typed in are: " + x.ToString() + " " + y.ToString() + " " + z.ToString() + ". All values must be above zero, please!");
}
}
So anyone who can help me to put the perlin noise code inside my code, so I would have the future to add perlin noise to my terrain.
And sorry for my English I am from the Netherlands.
Thanks in advance. (PS: If you don't understand me, ask me any questions)
if you're looking for a faster way to say "sort of $$anonymous$$ecraft terrain," it's "voxel."
Answer by Graham-Dunnett · Jan 11, 2013 at 11:27 AM
Just use one that someone has written already:
http://wiki.unity3d.com/index.php?title=TerrainPerlinNoise
Google is your friend.
Error: The script needs to derive from $$anonymous$$onobehaviour, what to do?
The text starts with "This Editor wizard ...", so it's an editor script and not a $$anonymous$$onoBehaviour script. Just place it in a folder named "editor". For example
Assets/editor/TerrainPerlinNoise.cs
When the script is compiled you should have a new menu item in called "Generate from Perlin Noise" inside your "Terrain" menu.
If you want to use it at runtime you have to adapt it into one of your scripts. If you have no idea how to do this, then you should start with something way simpler.
Answer by Bunny83 · Jan 11, 2013 at 11:50 AM
Just in case you've missed it, there's a Minecraft-starter-package out there for free.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Minecraft-like ore generation 1 Answer
Add perlin noise to blocky terrain 0 Answers
Random Terrain Generation (Trees, Details, Textures) by passing a Seed? 0 Answers
How exactly is Perlin Noise implemented? 4 Answers