# Substituting Sinus function with Perlin noise?

2D Perlin noise has an X and Y axis so it’s basically a zigzag function.

please explain how to use the Mathf.PerlinNoise instead of Mathf.Sin to set the mesh coordinates abit randomly.

``````// Code from procedural examples to sine-ify a mesh

var scale = 10.0;
var speed = 1.0;
private var baseHeight : Vector3[];

function Update () {
var mesh : Mesh = GetComponent(MeshFilter).mesh;

if (baseHeight == null)
baseHeight = mesh.vertices;

var vertices = new Vector3[baseHeight.Length];
for (var i=0;i<vertices.Length;i++)
{
var vertex = baseHeight*;*
``````

vertex.y += Mathf.Sin(baseHeight_.x ) * scale; //<<<—THIS LINE PLEASE
vertices = vertex;
* }
mesh.vertices = vertices;
mesh.RecalculateNormals();
}*
EDIT-okay so here is a three-dimensional Perlin mashed deformation script, there are other noise functions on the forums that may have more control of the noise.
var scale = 0.40;
var speed = 1.0;
private var baseHeight : Vector3[];_

function Update () {
* var mesh : Mesh = GetComponent(MeshFilter).mesh;*

* if (baseHeight == null)*
* baseHeight = mesh.vertices;*

* var vertices = new Vector3[baseHeight.Length];*
* for (var i=0;i<vertices.Length;i++)*
* {*
_ var vertex = baseHeight*;
vertex.y += Mathf.PerlinNoise(baseHeight.x3+77,12) * scale;

vertex.x += Mathf.PerlinNoise(baseHeight.z2+77,22) * scale;
vertex.z += Mathf.PerlinNoise(baseHeight.y3+77,42) * scale;

vertices = vertex;
* }
mesh.vertices = vertices;
mesh.RecalculateNormals();
}*_

The Perlin noise function accepts a pair of values, for your case you might consider feature baseHeight*.x and z into it. Send those numbers, or any transformation of them that amuses you, into the Perlin method and then scale the result similarly to how you are making use of Sin. Note that the returned value is in the range 0,1 and so if you want your results to be in the same range as your previous experiment then double the output from the noise function and subtract 1.0.*