Perlin Noise applied to plane, except endpoints

Here goes,

I have created a script that when applied to a plane it creates random hills and valleys as it should. Now here lies my question. How do I make the end points stop at 0 naturally. For example I would have a plane and in the center would be random hills and valleys but the edges would be flat. Here is my Perlin Noise Script;

    public float power = 3.0f;
	public float scale = 1.0f;
	private Vector2 v2SampleStart = new Vector2(0f, 0f);
	
	void Start () 
	{
		Noise ();
	}
	
	void Update () {
		if (Input.GetKeyDown (KeyCode.Space)) 
		{
			v2SampleStart = new Vector2(Random.Range (0.0f, 100.0f), Random.Range (0.0f, 100.0f));
			Noise();
		}
	}
	
	void Noise() {
		MeshFilter mf = GetComponent<MeshFilter>();
		Vector3[] vertices = mf.mesh.vertices;
		for (int i = 0; i < vertices.Length; i++) 
		{    
			float xCoord = v2SampleStart.x + vertices_.x  * scale;_

float yCoord = v2SampleStart.y + vertices_.z * scale;
vertices.y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power;
* }
mf.mesh.vertices = vertices;
mf.mesh.RecalculateBounds();
mf.mesh.RecalculateNormals();
}*
Thanks in advanced!_

1 Like

erm.

off the top of my head.

determine the total mesh size.

and use an exp rolloff beyond a certain x , y threshold taken absolutely from the center.

something like 0.9 of the radius/width (circle might be nice) would be a decent start value and tend toward zero after that with a factor.

just use the x,y since it looks like you know that already. so piece of cake.

As an aside there should be some way of dealing with the numbers offset absolutely to negate needing to know the direction of falloff but either way it’s calculable and the shortcut evades me.

But roughly. As a method:

if ( NeedsRolloffApplying(vertices*))*

vertices_.y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power * factor;
or just
vertices.y = (Mathf.PerlinNoise (xCoord, yCoord) - 0.5f) * power * factor;
and make the factor unity (err 1) in the central cases and toward zero where the x or y is greater 40% distance away from the central value exponentially._

So. No Code. But that’s what I would do.