it doesn’t give me any error any longer but it doesn’t change anything either I want to deform it a bit
if I change
xBase + 500;
yBase - 500;
code still works with no error when I click on terrain but I still see no difference on the terrain
using UnityEngine;
using System.Collections;
public class Terraform : MonoBehaviour {
public Terrain myTerrain ;
public int xBase = 0;
public int yBase = 0;
void OnMouseDown () {
myTerrain.terrainData.SetHeights(xBase,yBase,new float [myTerrain.terrainData.heightmapWidth , myTerrain.terrainData.heightmapHeight]);
}
}
Terrain Width 64
Terrain Height 600
Terrain Length 64
Heightmap Resolution 65
Detail Resolution 1024
Detail Resolution per patch 8
Control Texture resolution 512
Base Texture Resolution 1024
using UnityEngine;
using System.Collections;
public class Terraform : MonoBehaviour {
public Terrain terrain ;
public TerrainData tData;
public int xRes ;
public int yRes ;
public float[,] heights;
public Terrain myTerrain ;
public int PlayerXi ;
public int PlayerZi ;
private GameObject Player ;
void Start () {
Player = GameObject.Find("Camera") ;
tData = terrain.terrainData;
xRes = tData.heightmapWidth;
yRes = tData.heightmapHeight;
//terrain.activeTerrain.heightmapMaximumLOD = 0;
//something I didn't manage to translate from Java
}
void OnMouseDown() {
// we convert float of our position x in to int
PlayerXi = (int) Player.transform.position.x;
// we convert float of our position z in to int
PlayerZi = (int) Player.transform.position.z;
// we tell heights how big the map is
heights = tData.GetHeights(0, 0, xRes, yRes);
// we set z in to x AND x in to y
heights[PlayerZi,PlayerXi] = 0.01f;
tData.SetHeights(0, 0, heights);
}
IMPORTANT IF you want to be 1m/1m you need to have
Heightmap Resolution = Terrain Width + 1
// and if you have both different size I guess for
// 1 length you'll need to create a formula
IF I’m wrong please correct me but this code works thanks for all the help
IF anyone has simplest solution for setting where it should be deformed please post the code