# TerrainData.bounds Documentation

Hello,

I am trying to get the bounding box of a terrain so that I can check to see if Vector3 is inside of it and get the height of the terrain at that point. I found the TerrainData.bounds documentation and it has this to say:

What does that mean?

Creative use of the English language aside, is there an easy way to check if point is inside a terrain object?

Better yet, is there a way to force the check into two dimensions so that I can then call getTerrainHeight to get the height of the terrain at that position?

1 Like

Hi Rsteppanek,

Look at:

which helps. The Bounds for you will make your terrain covered completely by these 6 faces. This is done in local space. The TerrainData.bounds just implements this, and uses Transform.position to let you know more about your terrain in world space.

Creative use? Yes, use Transform.position to move the terrain into world space. You can now check whether the point (assume this is a world space point) is inside the box surrounding the terrain. The problem here is that this test does not return what you wantâ€¦ just whether the point is inside the box. So, checking the position of the point will need you to grab triangles and determine which side the point is. That I canâ€™t answer - maybe you have vertices that give a central position for particular parts of the terrain. Then you can work out how far away the point is from this relevant position. (Iâ€™m inventing thisâ€¦)

Terrain.activeTerrain.SampleHeight() ???

Giving you some answers - hope these help.

Thank you for the reply. Iâ€™m not sure what the API call for that looks like. If I have a terrain object â€śtâ€ť are you saying I need to call transform.position before checking its bounds? i.e.

t.Trasnform.position;
if(t.terrainData.bounds.contains(myPointVector)){
var height = t.SampleHeight(object_pos);
};

## â€”orâ€” Is it that I need to get the bounding box extents and add them to the position vector to get the actual bounds of the terrain object in the x and z plane? i.e.

``````public bool checkPointInclusion(Terrain t, Vector3 point){

var min = t.transform.position.x - t.terrainData.bounds.extents.x;
if (min < point.x) return false;

var max = t.terrainData.bounds.extents.x + t.transform.position.x;
if (max > point.x) return false;

var zmin = t.transform.position.z - t.terrainData.bounds.extents.z;
if (zmin < point.z) return false;

var zmax = t.terrainData.bounds.extents.z + t.transform.position.z;
if (zmax > point.z) return false;

return true;
}

if(checkPointInclusion(t,object_pos))
{
object_pos.y = t.SampleHeight(object_pos);
}
``````

The latter seems really verbose and I would think that the API would already provide a way to do this more succinctly.

A bit of a necro, but I figure others might come upon this thread to find the same answer you were looking for.

You need to add the terrain position to the terrain data bounds, like so:

``````Bounds worldBounds = new Bounds(terrain.terrainData.bounds.center + terrain.transform.position, terrain.terrainData.bounds.size);
``````
10 Likes