- Home /
Help Perlin Noise for Cubes?
I got this code from the wiki unity3d, i want blocks, no terrain. I don't understand PerlinNoise but is the only way to create random cubes like minecraft. I don't know other mode to make random cubes, help please or a simple code in C# or Js for cubes. Sorry bad english i'm from Argentina.
using UnityEditor;
using UnityEngine;
using System.Collections;
public class TerrainPerlinNoise : ScriptableWizard {
public float Tiling = 10.0f;
[MenuItem("Terrain/Generate from Perlin Noise")]
public static void CreateWizard(MenuCommand command)
{
ScriptableWizard.DisplayWizard("Perlin Noise Generation Wizard", typeof(TerrainPerlinNoise));
}
void OnWizardUpdate()
{
helpString = "This small generation tool allows you to generate perlin noise for your terrain.";
}
void OnWizardCreate()
{
GameObject obj = Selection.activeGameObject;
if (obj.GetComponent<Terrain>())
{
GenerateHeights(obj.GetComponent<Terrain>(), Tiling);
}
}
public void GenerateHeights(Terrain terrain, float tileSize)
{
float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight];
for (int i = 0; i < terrain.terrainData.heightmapWidth; i++)
{
for (int k = 0; k < terrain.terrainData.heightmapHeight; k++)
{
heights[i, k] = Mathf.PerlinNoise(((float)i / (float)terrain.terrainData.heightmapWidth) * tileSize, ((float)k / (float)terrain.terrainData.heightmapHeight) * tileSize)/10.0f;
}
}
terrain.terrainData.SetHeights(0, 0, heights);
}
}
Sorry, but this site is for specific questions, and not for "I found this script and I want to make it do something else, who can change it for me?".
Answer by MountDoomTeam · Feb 01, 2013 at 09:17 PM
Hello, here is a page that shows you what the Perlin noise is, http://answers.unity3d.com/questions/188721/creating-perlin-noise.html#answer-383517 it generates lots of little bumps like an irregular sinus. What you can do, is instantiate 100 blocks along the X axis, 100 blocks along the Y axis, keep their width and length the same but modify their height with Perlin noise function. to make a really nice bunch of hills, if you multiply 2 Perlin noise functions against each other, then they will make strange irregular hills, because 1x1 equals 1 and 0x0 equals 0, imagine multiplying 2 of the wiggles like in the picture on the link. It becomes a 3d Mountain scape. I would do you some code that I'm a bit tired right now!
private var rot : Quaternion;
rot.eulerAngles = Vector3(0, 0, 0);
var terraincube: GameObject;
function Start (){
for (var px:float = 0; px < 100; px ++) {
for (var py:float = 0; py< 100; py ++) {
var Perlin1 = Mathf.PerlinNoise(px/30, 76);
var Perlin2 = Mathf.PerlinNoise(py/30, 22);
Instantiate(terraincube, Vector3(py-50, Perlin1*40*Perlin2, px-50), rot);
}
}
}
Then please mark his answer as "accepted", and don't post comments in the "Your answer" field, use the "add new comment" button ins$$anonymous$$d.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092008im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What's wrong with this code? Perlin Noise 0 Answers
Perlin Noise Issue 0 Answers
Perlin noise tutorials ? 2 Answers
Perlin Noise Plane Manipulation 1 Answer
Basics of Perlin Noise? 1 Answer