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][1], 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 <em>= vertices _* Random.Range(1.0f, 1.1f);_</em>
* }*
* mesh.vertices = vertices;*
* mesh.RecalculateBounds();*
* mesh.RecalculateNormals();*
* }*
}
_*[1]: http://forum.unity3d.com/threads/198260-Spherical-Terrain-Shader*_