- Home /
Perlin Noise Plane Manipulation
i want to start using Perlin Noise to manipluate vertices on a plane but i have no idea how, how can i get data from a perlin noise to move vertices on the y axis? i have a for loop going through all the vertices but how do i get data from a perlin noise to give me a y position?
Answer by robertbu · Mar 15, 2013 at 10:55 PM
Use Mathf.PerlinNoise(). There is an example in the reference page that creates a grayscale texture. It should be fairly straight forward to modify the example to instead change the y values of your plane.
I've looked at that but I didn't now what to use for the y position
Below is an example script. You will have to adjust the power and scale parameters to fit the resolution of your plane. You can hit the space bar to generate a new starting point (i.e. sample another point on the plane). The CreatePlane script in the Wiki is a nice way to generate higher resolution planes. Note the noise seems to be reflected about the x axis, so using this script you can create an anchor (top left for example) that places the plane all on one side of the origin. Here is a sample output:
using UnityEngine;
using System.Collections;
public class PerlinNoisePlane : $$anonymous$$onoBehaviour {
public float power = 3.0f;
public float scale = 1.0f;
private Vector2 v2SampleStart = new Vector2(0f, 0f);
void Start () {
$$anonymous$$akeSomeNoise ();
}
void Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space)) {
v2SampleStart = new Vector2(Random.Range (0.0f, 100.0f), Random.Range (0.0f, 100.0f));
$$anonymous$$akeSomeNoise();
}
}
void $$anonymous$$akeSomeNoise() {
$$anonymous$$eshFilter mf = GetComponent<$$anonymous$$eshFilter>();
Vector3[] vertices = mf.mesh.vertices;
for (int i = 0; i < vertices.Length; i++) {
float xCoord = v2SampleStart.x + vertices[i].x * scale;
float yCoord = v2SampleStart.y + vertices[i].z * scale;
vertices[i].y = ($$anonymous$$athf.PerlinNoise (xCoord, yCoord) - 0.5f) * power;
}
mf.mesh.vertices = vertices;
mf.mesh.RecalculateBounds();
mf.mesh.RecalculateNormals();
}
}
[1]: http://wiki.unity3d.com/index.php?title=CreatePlane
Thank you so much ive been trying to do this for a long time but why does my plane not look as hilly as your picture? the hills on $$anonymous$$e are very small and when i ajust the power they become like sharp edges do you have a smooth function?
never $$anonymous$$d i had to change the scale thank you so much for this it helped loads
Your answer
Follow this Question
Related Questions
Change a plane's vertices positions in runtime using a 2D array 0 Answers
easy c# Simplex Noise script code 1 Answer
Using noise as texture 2 Answers
Applying noise to a texture 1 Answer
Animated distortion of vertices 1 Answer