- Home /
Question by
Wololo Plays · Mar 08, 2015 at 08:11 AM ·
javascriptgeneratormountainssetheights
How to join the generators?
Hello, I'm with a doubt: How can I join the terrain generator via texture with the generator of mountains? Translated: Bing (Portuguese for English)
function GerarMontanhas(){
var TamanhoMapa : int;
var Montanhas : float[,];
TamanhoMapa = Terreno.terrainData.heightmapResolution;
Montanhas = new float[TamanhoMapa,TamanhoMapa];
var Area = 50;
var Altura = 100.0/Terreno.terrainData.heightmapResolution;
//Gerar as Montanhas
var PontoX : float;
PontoX = Random.Range(100,500) - Terreno.transform.position.x;
PontoX= (PontoX*Terreno.terrainData.heightmapResolution)/Terreno.terrainData.size.x;
var PontoZ : float;
PontoZ = Random.Range(100,500) - Terreno.transform.position.z;
PontoZ= (PontoZ*Terreno.terrainData.heightmapResolution)/Terreno.terrainData.size.z;
i = Random.Range(0,Terreno.terrainData.heightmapResolution);
j = Random.Range(0,Terreno.terrainData.heightmapResolution);
for (var t = 0; t < 4; t++){
for (i=PontoX-Area; i<PontoX+Area;i++)
{
for (j=PontoZ-Area; j<PontoZ+Area;j++)
{
var MontanhasAux : float;
MontanhasAux = ((PontoX - i)*(PontoX - i))+((PontoZ - j)*(PontoZ - j));
var Area2 : float;
Area2 = Area*Area;
if (MontanhasAux<Area2)
{
Montanhas[j,i] += Altura - (Altura * (MontanhasAux/Area2));
}
}
}
PontoZ = PontoZ + 20;
PontoX = PontoX + 20;
}
Terreno.terrainData.SetHeights (0, 0, Montanhas);
}
function GenerateTerrain(tileSize: float) {
//Gerar o terreno
//QUANTO MAIOR O NUMERO, MAIS MONTANHAS EXISTIRAO...
var HM : float = Random.Range (20, 350);
//Quanto menores os números no intervalo número, maior as colinas / montanhas será
var divRange:float = Random.Range (15, 30);
var height = Terreno.terrainData.heightmapHeight;
var width = Terreno.terrainData.heightmapWidth;
var hts : float[,] = new float[width,height];
//Heights para nossas colinas / montanhas
for (var i :float = 0; i < width; i++) {
for (var k :float = 0; k < height; k++) {
hts [i, k] = Mathf.PerlinNoise ((i / width) * tileSize, (k / height) * tileSize) / divRange;
}
}
Terreno.terrainData.SetHeights (0, 0, hts);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613185310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I convert unityscript to boo? 0 Answers
Dynamically load UnityScript file 1 Answer
If you destroy a List of Class objects... 1 Answer
Do not destroy a transform 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers