private var rotation: Quaternion;
rotation.eulerAngles=Vector3(0,0,0);
private var startpos=Vector3(20,20,20);
var obj:GameObject;
var player:GameObject;
function Start(){
for(var xx:float=0; xx<75; xx++){
for(var yy:float=0; yy<75; yy++){
var perlin1=Mathf.PerlinNoise(xx/15,100);
var perlin2=Mathf.PerlinNoise(yy/15,100);
Instantiate(obj,Vector3(yy,Mathf.Round(perlin1*25*perlin2),xx),rotation);
}
}
Instantiate(player,startpos,rotation);
}
I guess what I’m asking, is how to use the perlin noise in the code above along with the mesh functions to make a random terrain. Now, I’m not asking anyone to write a script for me, but if someone could at least point me in the right direction with using the mesh functions along with perlin noise, I’d really appreciate it.
Instead of Instantiating obj at that Vector3 just put the Vector3 in an array and feed the final array to a Mesh instance. You’ll also need to give it a triangles array at the very least - of which there are examples of triangulation and procedural mesh generation floating around.
Also note that you could write Quaternion.identity instead of eulerAngles = new Vector3(,0,0,0) to represent “no rotation”
Thanks for both the replies. I like the sound of your idea KelsoMRK. I’ll definitely try that out when I get a chance. Thanks for the tip about Quaternion.identity too
I tried what you said, and put each vector into an array, and put those arrays into a Vector3 for the mesh.vertices. But I now found out you can’t put arrays into a Vector3?.. Also I have no clue how to do the triangles now that my attempt at putting arrays into a vector3 didn’t work out. Below I posted the actual code as well, as humiliating as it is
private var startpos=Vector3(20,20,20);
var obj:GameObject;
var player:GameObject;
function Start(){
for(var xx:float=0; xx<75; xx++){
for(var yy:float=0; yy<75; yy++){
var perlin1=Mathf#PerlinNoise(xx/15,100);
var perlin2=Mathf#PerlinNoise(yy/15,100);
//Instantiate(obj,Vector3(yy,Mathf.Round(perlin1*25*perlin2),xx)Quaternion.identity);
var mesh:Mesh=GetComponent(MeshFilter).mesh;
var vertsx:int[]=new int[yy];
var vertsy:int[]=new int[Mathf.Round(perlin1*25*perlin2)];
var vertsz:int[]=new int[xx];
mesh.vertices=Vector3(vertsx,vertsy,vertsz);
//trianglulation...?
}
}
Instantiate(player,startpos,Quaternion.identity);
}