- Home /
TerrainData.GetHeights NEED HELP
Im Trying to Make a Terrian Paint Brush but i get a error
UnityException: Trying to access out-of-bounds terrain height information.
public class TerrianBrush : MonoBehaviour {
public Vector3 brushPostion;
public float[,] lastHight;
public Ray ray;
public RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray,out hit)) {
brushPostion = hit.point;
}
GameObject.Find("Brush").transform.position = brushPostion;
if (Input.GetMouseButton(0)) {
lastHight = Terrain.activeTerrain.terrainData.GetHeights(Mathf.RoundToInt(brushPostion.x), Mathf.RoundToInt(brushPostion.y),10,10);
}
}
}
Answer by Yanger_xy · Jun 10, 2011 at 07:41 AM
Apparently, you are accessing the unavailable memory."Trying to access out-of-bounds terrain height information." I suggest you check GetHeights' param, as far as i know, for example, if your terrain is 10 by 10, and your brush point is just at the right-top corner, "Trying to access out-of-bounds terrain height information." will happen. so check your params first. Good luck
yea thanks i did a bit more research and it now works fine
Answer by biohazard · Jun 10, 2011 at 07:42 AM
Try This. http://unity3d.com/support/documentation/ScriptReference/TerrainData-heightmapHeight.html
:)
This might also be helping.
http://unity3d.com/support/documentation/ScriptReference/TerrainData.GetHeight.html
:)
Your answer
Follow this Question
Related Questions
Terrain Brush Problem 2 Answers
Edit Terrain Script 0 Answers
Terrain brushes cannot be set - BUG 1 Answer
[Blender] Sculpt high detail with custom brush over low poly terrain 0 Answers
Set Terrain Resolution 1 Answer