x


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);
    }
}

}

more ▼

asked Jun 10 '11 at 07:33 AM

pietothemax gravatar image

pietothemax
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jun 10 '11 at 07:41 AM

Yanger_xy gravatar image

Yanger_xy
270 22 25 33

yea thanks i did a bit more research and it now works fine

Jun 12 '11 at 02:37 AM pietothemax
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1478
x22
x6

asked: Jun 10 '11 at 07:33 AM

Seen: 1528 times

Last Updated: Jun 12 '11 at 02:37 AM