- Home /
Generating Vector3s with Perlin Noise?
Hiya, everyone. I've been trying to generate a planet. I've created an icosphere mesh and am trying to manipulate the vertices in a way that simulates terrain. Here's the code I have so far, and it works for what it's meant to do; it manipulates the sphere mesh somewhat randomly, but doesn't quite look like natural terrain.
I have been looking into Perlin noise generation to solve this issue as per this thread, but I can't quite figure out how to reliably generate Vector3s based on Perlin noise (due to my personal impairment in mathematics and mediocre documentation on the PerlinNoise function). Mayhaps one of you can help nudge me in the right direction?
using UnityEngine;
using System.Collections;
public class PerlinTerrain : MonoBehaviour
{
private Vector3[] vertices;
void Start ()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
for (var i=0; i < vertices.Length; i++)
{
vertices[i] = vertices[i] * Random.Range(1.0f, 1.1f);
}
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}
Answer by Taryndactyl · Sep 03, 2013 at 07:06 AM
Hey sorry I don't have time to really explain or answer right now unfortunately. But I did follow this tutorial and it may help you out, cheers!
Interesting to read, unfortunately it didn't help much. I think what I need is a method by which I can extract an array of floats from the Perlin noise function that I can then apply to the respective vertices on my mesh.
If I'm understanding correctly you would use $$anonymous$$athf.PerlinNoise on every vertex then apply the visual transformations.
$$anonymous$$aybe a For loop containing your perlin setup then a for inside of that, that will apply the changes?
Essentially, yes, that's what I'd like to have. Unfortunately, I haven't really got a solid enough understanding of Perlin noise to construct a "perlin setup." $$anonymous$$aybe you could help with that?