I’ve been looking about on the script reference for a good noise function and Perlin noise seems to be what I need. I’m trying to pseudo-randomly generate planet-like meshes at runtime using a sphere mesh like so:
using UnityEngine;
using System.Collections;
public class PerlinTerrain : MonoBehaviour
{
private Vector3[] vertices;
void Start ()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
for (int i = 0; i < vertices.Length; i++)
{
vertices <em>= vertices _* Random.Range(0.9f, 1.1f);_</em>
* }*
* mesh.vertices = vertices;*
* mesh.RecalculateBounds();*
* mesh.RecalculateNormals();*
* }*
}
That code does what it’s supposed to, although instead of using Random.Range, I’d like for vertices to be multiplied by a value that’s extrapolated from a Perlin noise function. How might I go about doing this? I’ve been looking around for sufficient documentation for so long that I actually went to the second page of Google.